【发布时间】:2015-06-10 16:23:41
【问题描述】:
我要创建 2GB 文件的 zip 文件时如何找出问题。
错误
file_get_contents():内容从 2147483648 截断到 2147483647 字节
致命错误:内存不足(已分配 2151677952)(试图分配 18446744071562067968 字节)在
我正在使用专用服务器并且已经设置了memory_limit,max_execution_time,max_upload_filesize,max_post_size。但这对我不起作用。请检查我的代码并让我知道我做错了什么-
创建新的 zip 对象
$zip = new ZipArchive();
# create a temp file & open it
$tmp_file = tempnam('.','');
$zip->open($tmp_file, ZipArchive::CREATE);
# loop through each file
foreach($files as $file){
# download file
$download_file = file_get_contents($file_path.'/'.$file);
#add it to the zip
$zip->addFromString(basename($file_path.'/'.$file),$download_file);
}
# close zip
$zip->close();
$zip_name = $last_seg.'.zip';
# send the file to the browser as a download
header("Content-disposition: attachment; filename=$zip_name");
header('Content-type: application/zip');
readfile($tmp_file);
【问题讨论】:
-
试试这里提供的解决方案stackoverflow.com/questions/6282887/…这是一个内存限制问题,而且您的文件太大。
-
同时检查这个问题/答案stackoverflow.com/questions/5745255/…
-
非常感谢,这可能是重复的问题,但在尝试了这里所有可用的解决方案后,我又问了一遍。我试图从 WHM 增加内存限制但没有工作:(
-
消息说您正在尝试分配 18446744 TeraBytes。我认为您不仅应该调整内存限制,还应该购买更多的 RAM...
标签: php file http-headers zip memory-limit