Zip not uploading :- (


Zip not uploading :- (

由于某些原因,当尝试上传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;
        }
    }
}

在继续执行一组可能完全无用的操作之前,您确实需要检查上传是否成功:

function uploadProof ( $file, $email ) {
   if ($file['error'] !== UPLOAD_ERR_OK) {
       die("Upload failed with error code " . $file['error']);
   }
   ...
}

错误码定义在这里