我正在用php创建包含视频之类的大文件的zip文件。 ZIP应该是500mb左右,而当我尝试使用php时,它会因为504 Gateway TimeOut而崩溃。我想添加进度条或其他东西以避免服务器饱和,我认为添加文件时关键在foreach中。
foreach($post['files'] as $file) {
$zip->addFile($file,basename($file));
}
我已经设置了max_execution_time
ini_set('max_execution_time', 0);
任何想法都是最好的方法吗?
完整代码:
<?php
set_time_limit(0);
ini_set('max_execution_time', 0);
if(isset($_POST['files']))
{ $error = ""; //error holder
{
$post = $_POST;
$file_folder = "files/"; // folder to load files
if(extension_loaded('zip'))
{
// Checking ZIP extension is available
if(isset($post['files']) and count($post['files']) > 0)
{
// Checking files are selected
$casting_titulo = $post['casting_titulo'];
$zip = new ZipArchive(); // Load zip library
$zip_name = $titulo."cast.zip"; // Zip name
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE)
{
// Opening zip file to load files
$error .= "* Sorry ZIP creation failed at this time";
}
foreach($post['files'] as $file) {
$zip->addFile($file,basename($file));
}
$zip->close();
if(file_exists($zip_name))
{
// push to download the zip
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_name);
// remove zip file is exists in temp path
unlink($zip_name);
}}
else $error .= "* Please select file to zip "; }
else $error .= "* You dont have ZIP extension"; }
}
?>