【发布时间】:2015-06-29 16:26:18
【问题描述】:
上传文件工作正常,文件大小小于 2.9 MB,但我的 phpinfo (localhost) 显示 upload_max_filesize 64M。
当尝试上传较大的文件时,表单提交后 $_POST 为空且没有上传文件。
这是我的代码:
<?php
function fileUpload($attachment){
$target_file = UPLOADDIR.basename($attachment["name"]);
if (file_exists($target_file)) {
return "Sorry, file already exists.";
}
if (move_uploaded_file($attachment["tmp_name"], $target_file)) {
return "The file ". basename( $attachment["name"]). " has been uploaded.";
} else {
return $attachment;
return "Sorry, there was an error uploading your file.";
}
}
if(isset($_POST["submit"])) {
fileUpload($_FILES['fileToUpload'])
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
【问题讨论】:
-
查看php执行时间
-
你也应该检查 post_max_size stackoverflow.com/questions/6135427/…
-
你的意思是 max_execution_time 它目前是 120。我只是在寻找最大大约 5 MB 的文件上传大小。
-
@steven post_max_size 只有 3M。这是个问题吗?我需要增加它吗?
-
是的,它应该等于或大于upload_max_filesize
标签: php html file-upload