出于某种原因,在尝试上传zip文件时,此函数始终返回false。这些目录都设置为0777以获取权限。我很难过可能出错的地方。
function uploadProof ( $file, $email )
{
// Check or create for existing directory
if ( !is_dir('client_files/'.$email))
{
mkdir('client_files/'.$email);
if ( !is_dir('client_files/'.$email.'/proof/'))
{
mkdir('client_files/'.$email.'/proof/');
}
}
// Target path
$target_path = 'client_files/'.$email.'/proof/';
// File information
$filename = date('Y_M_D').$email.'.zip';
$tmp_name = $file['tmp_name'];
$filesize = $file['size'];
// Blacklist and Max file info
$max_allowed = (1024 * 1024) * 99; // 99 MB
$blacklist = array(
'.pl', '.php', '.phtml', '.php3', '.php4', '.php5'
);
// Check filename
foreach ( $blacklist as $nope)
{
if ( preg_match("/$nope\$/i", $filename))
{
die("As previously stated, we do not allow php files of any type\n
to be uploaded to our server.\n\n");
}
}
// Check filesize
if ( $filesize > $max_allowed)
{
die("File is too big, file needs to be less than <em>20MB</em> in size.");
}
else
{
$target = $target_path.$filename;
if (move_uploaded_file($tmp_name, $target))
{
return true;
}
else
{
return false;
}
}
}
答案 0 :(得分:2)
在继续执行可能完全无用的操作之前,您需要检查上传是否实际成功:
function uploadProof ( $file, $email ) {
if ($file['error'] !== UPLOAD_ERR_OK) {
die("Upload failed with error code " . $file['error']);
}
...
}
错误代码定义为here。