我的表單很簡單,我認爲上傳php很簡單,但是當我測試它的結果是不尋常的。我可以上傳任何文件和任何大小,它會工作。我以爲我寫了它來限制某些文件和大小......我哪裏錯了?上傳器文件上傳任何東西
形式:
<form enctype="multipart/form-data" action="upload_file.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>
upload_file.php:
$target = "uploads/";
$target = $target . basename($_FILES['uploaded']['name']) ;
$ok = 1;
$uploaded = $_POST['uploaded'];
//This is our size condition
if ($uploaded_size > 3000){
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type == "text/php"){
echo "No PHP files are allowed for upload.<br>";
$ok = 0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok == 0){
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded";
}
else{
echo "Sorry, there was a problem uploading your file.";
}
}
你在哪裏$ uploaded_type和$ uploaded_size var? – Yordi 2013-04-29 20:16:21
這裏是一個非常簡單明確的文章http://www.w3schools.com/php/php_file_upload.asp – Vector 2013-04-29 20:18:55
@Vector:哦不,不建議w3schools.com作爲參考。它充滿了錯誤,請參閱http://w3fools.com – 2013-04-29 20:19:25