2013-10-26 71 views
0

刷新php頁面後重新提交 - 爲什麼刷新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("abcdefghijklmnopqrstuvwxyz", 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 
} 
?> 
+0

你可以添加你的表單,以便我們看到該動作。 –

+0

請你解釋一下,我們不能幫你這樣做! –

+0

我編輯它,看我的表格代碼 – user2719452

回答

0

好,

每個窗體後提交後數據仍保留在會話中。 你可以通過這種方式來完成腳本。

方法1:

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

或者,您CA做

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

其中[YOUR URL]將是你想要的文件上傳被處理後去的URL。

之後,所以提交的數據將不會再被保存。

+0

我試試看,這是無效的,編輯我的代碼來幫助我請。 – user2719452