Zip 未上传:- (

发布于 2024-11-25 01:29:09 字数 1448 浏览 0 评论 0 原文

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

For some reason when trying to upload a zip file this function always returns false. The directories are all set to 0777 for permissions. I'm stumped as to what could be wrong.

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;
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ双果 2024-12-02 01:29:09

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

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

错误代码定义为 此处

You do need to check if the upload actually succeeded, before going on to do what might be a totally useless set of operations:

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

The error codes are defined here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文