我正在使用 CakePHP 中的文件和文件夹。现在一切正常,并且按照我想要的方式进行。但是,当压缩文件时,我收到以下错误消息:
Error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 240047685 bytes)
现在压缩较小的文件,很好!我什至完成了大约 10MB 大小的文件,没有任何问题,但是更大的压缩似乎有问题。
现在我已将以下内容添加到我的 .htaccess 文件中并制作了一个 php.ini 文件,因为我认为这可能是问题所在。
php_value upload_max_filesize 640000000M
php_value post_max_size 640000000M
php_value max_execution_time 30000000
php_value max_input_time 30000000
直到我发现一些帖子指出 PHP 作为 4GB 文件限制。好吧,即使是这样,为什么我的 zip 文件不做这个文件(只有大约 245mb)。
public function ZippingMyData() {
$UserStartPath = '/data-files/tmp/';
$MyFileData = $this->data['ZipData']; //this is the files selected from a form!
foreach($MyFileData as $DataKey => $DataValue) {
$files = array($UserStartPath.$DataValue);
$zipname = 'file.zip';
$zip = new ZipArchive();
$zip_name = time().".zip"; // Zip name
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($files as $file) {
$path = $file;
if(file_exists($path)) {
$zip->addFromString(basename($path), file_get_contents($path));
} else {
echo"file does not exist";
}
} //End of foreach loop for $files
} //End of foreach for $myfiledata
$this->set('ZipName', $zip_name);
$this->set('ZipFiles', $MyFileData);
$zip->close();
copy($zip_name,$UserStartPath.$zip_name);
unlink($zip_name); //After copy, remove temp file.
$this->render('/Pages/download');
} //End of function
关于我哪里出错的任何想法?我会声明这不是我的代码,我在其他帖子中找到了一些代码并对其进行了更改以适合我的项目需求!
欢迎大家帮忙...
谢谢
格伦。