刷新php页面后重新提交 - 为什么

时间:2013-10-26 11:45:58

标签: php submit refresh form-submit page-refresh

刷新php页面后重新提交 - 为什么

为什么?

刷新后我不想重新提交!

任何帮助?

我尝试更多解决方案

但所有解决方案都无效!

这是我的代码,

如果你有解决方案

请..

你编辑我的代码来帮助我,

感谢。

这是我的表单代码

<form id="uploadedfile" name="uploadedfile" enctype="multipart/form-data" action="upload.php" method="POST">
<input name="uploadedfile" type="file" />
<input type="submit" value="upload" />
</form>

这是upload.php代码:

<?php
$allowedExts = array("gif", "jpeg", "jpg", "png", "zip", "pdf", "docx", "rar", "txt", "doc");
$temp = explode(".", $_FILES["uploadedfile"]["name"]);
$extension = end($temp);
$newname = $extension.'_'.substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyz", 7)), 4, 7);
$imglink = 'attachment/attachment_file_';
$uploaded = $imglink .$newname.'.'.$extension;
if ((($_FILES["uploadedfile"]["type"] == "image/jpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/jpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/jpg")
|| ($_FILES["uploadedfile"]["type"] == "image/pjpeg")
|| ($_FILES["uploadedfile"]["type"] == "image/x-png")
|| ($_FILES["uploadedfile"]["type"] == "image/gif")
|| ($_FILES["uploadedfile"]["type"] == "image/png")
|| ($_FILES["uploadedfile"]["type"] == "application/msword")
|| ($_FILES["uploadedfile"]["type"] == "text/plain")
|| ($_FILES["uploadedfile"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document")
|| ($_FILES["uploadedfile"]["type"] == "application/pdf")
|| ($_FILES["uploadedfile"]["type"] == "application/x-rar-compressed")
|| ($_FILES["uploadedfile"]["type"] == "application/x-zip-compressed")
|| ($_FILES["uploadedfile"]["type"] == "application/zip")
|| ($_FILES["uploadedfile"]["type"] == "multipart/x-zip")
|| ($_FILES["uploadedfile"]["type"] == "application/x-compressed")
|| ($_FILES["uploadedfile"]["type"] == "application/octet-stream"))
&& ($_FILES["uploadedfile"]["size"] < 5242880) // Max size is 5MB
&& in_array($extension, $allowedExts))
{   
move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],
$uploaded );
echo '<a target="_blank" href="'.$uploaded.'">click</a>';
echo '<h3>'.$uploaded.'</h3>';
}
if($_FILES["uploadedfile"]["error"] > 0){
echo '<h3>Please choose file to upload it!</h3>'; // If you don't choose file
}
elseif(!in_array($extension, $allowedExts)){
echo '<h3>This extension is not allowed!</h3>'; // If you choose file not allowed
}
elseif($_FILES["uploadedfile"]["size"] > 5242880){
echo "Big size!"; // If you choose big file
}
?>

1 个答案:

答案 0 :(得分:0)

那么,

在每个表单提交后,帖子数据仍保留在会话中。 你可以用这种方式完成脚本。

方法1:

 unset($_POST);
 unset($_FILES);
 unset($_REQUEST);

或者,你可以做一个

 header('Location:[YOUR URL]');

[您的网址]将成为处理文件上传后您想要去的网址。

之后,提交的数据将不再保留。