根据您要上传的文件类型,您可以尝试将压缩文件发送到服务器,并在上传完成后将其解压缩。
您可以在php here中查看关于zip函数的更多信息。
要压缩一个文件: 来源:http://davidwalsh.name/create-zip-php
/* creates a compressed zip file */
function create_zip($files = array(),$destination = '',$overwrite = false) {
//if the zip file already exists and overwrite is false, return false
if(file_exists($destination) && !$overwrite) { return false; }
//vars
$valid_files = array();
//if files were passed in...
if(is_array($files)) {
//cycle through each file
foreach($files as $file) {
//make sure the file exists
if(file_exists($file)) {
$valid_files[] = $file;
}
}
}
//if we have good files...
if(count($valid_files)) {
//create the archive
$zip = new ZipArchive();
if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
return false;
}
//add the files
foreach($valid_files as $file) {
$zip->addFile($file,$file);
}
//debug
//echo 'The zip archive contains ',$zip->numFiles,' files with a status of ',$zip->status;
//close the zip -- done!
$zip->close();
//check to make sure the file exists
return file_exists($destination);
}
else
{
return false;
}
}
要在服务器解压缩文件:
<?php
$zip = new ZipArchive;
$res = $zip->open('file.zip');
if ($res === TRUE) {
$zip->extractTo('/myzips/extract_path/');
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
}
?>
或启动上传作为后台进程,所以你不会需要等待上传完成,然后做其他的事情,而上传是一个后台进程,你可以做其他的东西,而文件上传在后台。 **注意**这种方式只有在您不必马上处理上传的文件时才可行。 – 2015-02-05 12:52:49
但是如果我必须加快速度会怎样。 – 2015-02-05 12:59:05
嗯,如果你的上传速度已经是20MB/s,你真的无能为力了,只能购买更快的上传连接。 (如果你的上传速度明显慢于你的最高速度,我会尝试同时上传较少的文件或以某种方式更改脚本。) – 2015-02-05 13:13:38