【问题标题】:File upload and confirmation page before submission提交前的文件上传和确认页面
【发布时间】:2012-03-28 12:23:15
【问题描述】:

我正在尝试在从表单提交数据之前创建一个“请确认”页面。该表单有一个文件上传字段。 如何传递上传字段中提交的内容的值,以便他们确认并再次点击提交?

我将发布到隐藏字段中的其余数据并回显这些值以便他们确认。

如何使用上传的$_FILE 完成此操作

首页:

<form action="confirm.php" method="post">
<input type="text" name="name"/>
<input type="file" name="attachment"/>
<input type="submit" name="submit" value="Submit"/>
</form>

确认.php

<form action="submit_data.php" method="post">
Your Name: <? echo $_POST['name']; ?>
<input type="hidden" name="name" value="<? echo $_POST['name']; ?>"/>

//HERE IS WERE I NEED TO STORE THE FILE INFO 
Your File Name: <? echo $_FILES['attachment']['name']; ?>
<input type="hidden" name="<? echo $_FILES['attachment']; ?>"/>

<input type="submit" name="submit" value="Submit"/>
</form>

【问题讨论】:

    标签: php forms file-upload


    【解决方案1】:

    您必须在confirm.php 中处理和存储图像。然后存储对处理后图像的引用:

    // pseudo code for confirm.php
    process image
      if error back to form.php
      move image to tmp directory.
    inject path of tmp file into hidden field
    
    // submit_data.php
    grap temp path from hidden field.
    copy to final location
    

    【讨论】:

    • 我尝试了您的概念,但是在 submit_data.php 页面上,当我从 post 变量中引用 $tmp_path 时,我收到以下错误“警告:复制(/tmp/phpFC4G3c)[function.copy] : 无法打开流: 没有这样的文件或目录..."
    • 在您的confirm.php 页面上,您需要将tmp 文件从/tmp/* 移动到另一个目录。处理完页面后,您的 http 服务器很可能会删除此文件。 $newPath = '文件/somefile.upload';复制($tmpPath, $newPath);
    【解决方案2】:

    在 Confirm.php 页面中添加一个用于提交的 javascript onclick 函数,如下所示

    <script type="text/javascript">
    function show_confirm()
    {
    var r=confirm("Do you wish to upload the file");
    if (r==true)
      {
     return true;
      }
    else
      {
     return false;
      }
     return false;
    }
    </script>
    
    <form action="confirm.php" method="post">
        <input type="text" name="name"/>
        <input type="file" name="attachment"/>
        <input type="submit" name="submit" value="Submit"
         onclick='return show_confirm();'/>
    </form>
    

    【讨论】:

      猜你喜欢
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      • 2016-09-06
      • 2011-09-21
      • 2011-09-23
      相关资源
      最近更新 更多