用php上传大文件
在PHP中如何上传大于2MB的文件,我在互联网上搜索并更改了用php上传大文件,php,Php,在PHP中如何上传大于2MB的文件,我在互联网上搜索并更改了PHP.ini文件,行是:“upload\u max\u filesize=200M”,但我仍然无法上传2MB的文件 有什么问题吗 请帮帮我。提前谢谢。正如您所猜测的,您必须设置 但是您还必须设置(引用): 设置允许的post数据的最大大小。 此设置也会影响文件 上传。要上载大文件,此 值必须大于 上传最大文件大小 还有其他可能限制这一点的选项: max_input_time = 600 php_value max_execution
PHP.ini
文件,行是:“upload\u max\u filesize=200M”
,但我仍然无法上传2MB的文件
有什么问题吗
请帮帮我。提前谢谢。正如您所猜测的,您必须设置
但是您还必须设置(引用): 设置允许的post数据的最大大小。
此设置也会影响文件 上传。要上载大文件,此 值必须大于
上传最大文件大小
还有其他可能限制这一点的选项:
max_input_time = 600
php_value max_execution_time = 600
post_max_size = 200M
(…并重新启动Apache)将以下代码放在.htaccess文件中并保存它
php_value upload_max_filesize 200M
php_value post_max_size 200M
php_value max_input_time 2000
尝试在PHP脚本中设置它(在顶部)
获取php.ini-dist文件
- 编辑它以设置上面显示的正确值
- 将其重命名为php.ini
- 将其复制到WINDOWS目录中
- 重新启动Apache
upload\u max\u filesize
并设置post\u max\u size
,然后重新启动服务器upload\u max\u filesize
和post\u max\u size
的值已更改为您所需的值这对我很有用,希望有帮助。要上传更大的文件,需要更改/增加php.ini文件中post_max_size和upload_max_filesize指令的值
上载\u最大\u文件大小=200M
立柱最大尺寸=201M
这会将单个文件的上载限制从默认的2MB增加到200MB。要上载大文件(>5MB),我使用chuck上载方法。
/**
* @param $file
* @param $fileSize
* @param $name
* @return int
*/
public function chunkUpload($file, $fileSize, $applicantID, $name) {
$targetFile = 'upload/'. $name;
$chunkSize = 256; // chunk in bytes
$uploadStart = 0;
$handle = fopen($file, "rb");
$fp = fopen($targetFile, 'w');
# Start uploading
try {
while($uploadStart < $fileSize) {
$contents = fread($handle, $chunkSize);
fwrite($fp, $contents);
$uploadStart += strlen($contents);
fseek($handle, $uploadStart);
}
fclose($handle);
fclose($fp);
return 200;
} catch (\Exception $e) {
return 400;
}
}
/**
*@param$文件
*@param$fileSize
*@param$name
*@return int
*/
公共函数chunkUpload($file、$fileSize、$applicationId、$name){
$targetFile='upload/'。$name;
$chunkSize=256;//块(字节)
$uploadStart=0;
$handle=fopen($file,“rb”);
$fp=fopen($targetFile,'w');
#开始上传
试一试{
而($uploadStart<$fileSize){
$contents=fread($handle,$chunkSize);
fwrite($fp,$contents);
$uploadStart+=strlen($contents);
fseek($handle,$uploadStart);
}
fclose($handle);
fclose($fp);
返回200;
}捕获(\异常$e){
返回400;
}
}
以这种方式更改了服务器设置
memory_limit = 250M //The maximum amount of memory in bytes a script is allowed to allocate.
max_input_time = 600 //The maximum time in seconds a script is allowed to parse input data.
max_execution_time = 600 //The maximum time in seconds a script is allowed to run before it is terminated.
post_max_size = 200M //The maximum size in bytes of data that can be posted with the POST method. Typically, should be larger than upload_max_filesize and smaller than memory_limit.
upload_max_filesize = 100M //The maximum size in bytes of an uploaded file.
你的
不能
是什么意思?你能说得更具体些吗?错误日志中的任何错误都会非常有用。您是在共享主机上运行还是在本地计算机上运行?关于堆栈溢出,有很多问题。你查过了吗?我是单身system@karthick:什么是“无法获得输出”?请你说得更具体些。请准确描述您看到的内容,以及您采取了哪些步骤来查看它。phpinfo()
表明了什么?@Pascal MARTIN:PHP版本5.2。6@karthickphpinfo()对这些值表示什么?@karphing那么,您编辑的php.ini是错误的。phpinfo对加载的php.ini说了什么?你在编辑哪一个?你重启服务器了吗?@karthigh:你忘了重启Apache了吗?我更改了:php\u value upload\u max\u filesize 32M php\u value post\u max\u size 60M php\u value max\u execution\u time 500 php\u value max\u input\u time 500 max\u execution\u time在这里做什么?max\u execution\u time用于脚本的最长生存时间以及脚本在接受input@karthick只有在文件完成上载后,web服务器才会调用PHP脚本。@karthick:您必须重新启动web服务器才能使其生效。由于设置太晚,该脚本无法工作。PHP脚本本身不处理上载。实际上只有在上传完成后才会调用它。@Efazati,条目可以在php.ini、.htaccess或httpd.conf中设置,我不知道这一点。谢谢@斯帕雷尔上校,我想你是对的。@Col.Sharpnel:我做了你写的,但仍在phpinfo节目中2MB@karthick好的,你必须参考wamp文档来编辑php.ini…无论如何,谢谢Sharpnel上校,我会亲自尝试,如果我上传成功,我会告诉你。
memory_limit = 250M //The maximum amount of memory in bytes a script is allowed to allocate.
max_input_time = 600 //The maximum time in seconds a script is allowed to parse input data.
max_execution_time = 600 //The maximum time in seconds a script is allowed to run before it is terminated.
post_max_size = 200M //The maximum size in bytes of data that can be posted with the POST method. Typically, should be larger than upload_max_filesize and smaller than memory_limit.
upload_max_filesize = 100M //The maximum size in bytes of an uploaded file.