限制上传文件
问题描述:
Possible Duplicate:
POST Content-Length exceeds the limit
PHP Warning: POST Content-Length of 113 bytes exceeds the limit of -1988100096 bytes in Unknown限制上传文件
我要上传图片的形式,我的测试,如果我上传的图片,其中有例如9 MB的大小,PHP将返回错误:
POST Content-Length of 10194008 bytes exceeds the limit of 8388608 bytes in Unknown on line 0
我要那个不要上传文件超过2 MB,在第一行我有这样的代码:
if (!empty($_FILES['main_photo']['name'])) {
if ($_FILES['main_photo']['size'] > 1024 * 1024 * 2) {
header("Location: index.php");
exit();
}
}
,但这个错误仍显示,请告诉做什么,我想,如果文件超过2 MB,只是:
header("Location: index.php");
答
您尝试上传的文件大于在php.ini中设置的配置大小。走在php.ini中并修改这些值来2MB或更大允许更大上传:
upload_max_filesize
post_max_size <-- This one appears to be your biggest issue
那么你的代码应该工作。
答
在php.ini找upload_max_filesize
和post_max_size
,并设置到合适的大小:
upload_max_filesize = 20M
post_max_size = 20M
只有在改变,你可以添加自己的重定向代码。
如果您无法访问您的php.ini(共享主机)尝试在.htaccess:
php_value upload_max_filesize 20M
php_value post_max_size 20M
答
您的服务器可能已经设置为大小限制为8兆,我想你的代码是好。它的一个服务器问题尝试使用ini_set
设置upload_max_filesize
更多。如果你是一个商业服务器,而不是你自己的,请尝试联系管理员
你应该先检查'$ _FILES ['main_photo'] ['error']' – 2012-08-11 14:27:40