下面的脚本处理.zip文件的上传,提取和传输
我在一个服务器上发生了一个奇怪的问题(目前只有一个),当zip文件包含名为“cache”的文件夹时,服务器会在传输文件之前重置连接。
任何可能导致此问题的想法?将文件夹名称更改为不包含单词“-cache”的任何内容可以解决问题。
有问题的foldername是“gravatar-cache”
<?php
function openZip($file_to_open) {
global $target;
global $wp_filesystem;
if(class_exists('ZipArchive'))
{
$zip = new ZipArchive();
$x = $zip->open($file_to_open);
if($x === true)
{
$zip->extractTo($target);
$zip->close();
unlink($file_to_open);
} else {
die("There was a problem. Please try again!");
}
}
else
{
WP_Filesystem();
$my_dirs = '';
_unzip_file_pclzip($file_to_open, $target, $my_dirs);
unlink($file_to_open);
}
}
if(isset($_FILES['fupload'])) {
$filename = $_FILES['fupload']['name'];
$source = $_FILES['fupload']['tmp_name'];
$type = $_FILES['fupload']['type'];
$name = explode('.', $filename);
global $templateName;
$templateName = strtolower($name[0]);
// permission settings for newly created folders
$chmod = 0755;
// Ensures that the correct file was chosen
$accepted_types = array('application/zip','application/x-zip-compressed','multipart/x-zip','application/s-compressed','image/jpeg');
foreach($accepted_types as $mime_type) {
if($mime_type == $type)
{
$okay = true;
break;
}
}
//Safari and Chrome don't register zip mime types. Something better could be used here.
$saved_file_location = $target . $filename;
if (strtolower($name[1]) =='zip')
{
if (move_uploaded_file($source, $saved_file_location))
{
//unzip_file($saved_file_location, $target);
openZip($saved_file_location);
}
else
{
die();
}
}
}