提交前的文件上传和确认页面

时间:2012-03-12 03:20:43

标签: php forms file-upload

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

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

如何使用上传的$_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>

Confirm.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>

2 个答案:

答案 0 :(得分:3)

你必须处理&amp;将图像存储在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

答案 1 :(得分:0)

在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>