【发布时间】:2011-07-18 19:38:22
【问题描述】:
由于某种原因,在尝试上传 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;
}
}
}
【问题讨论】:
-
请张贴 print_r( $_FILES );
-
Array ( [name] => BLAHBLAHfilename.zip [type] => application/zip [tmp_name] => /Applications/MAMP/tmp/php/phpzDwFiL [error] => 0 [size] => 1358091 )