0

我创建了一个上传站点,由于某种原因,处理 .dmg 文件在下载时总是最终损坏。任何其他文件类型都可以正常工作,但如果有人上传 .dmg 然后下载它,Mac OS X 会说它已损坏,但这不会发生在任何其他文件上。有没有其他人有这个问题。

这是我的上传代码:

$temp_file = $_FILES['Filedata']['tmp_name'];
    $ext = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION);
    $new_file_name = md5(uniqid(rand(), true));
    $target_file = rtrim(enc_target_path, '/') . '/' . $new_file_name . '.enc.' . $ext;

    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
    $key = substr(md5('some_salt' . $password, true) . md5($password . 'more_salt', true), 0, 24);
    $opts = array('iv' => $iv, 'key' => $key);

    $my_file = fopen($temp_file, 'rb');

    $encrypted_file_name = $target_file;
    $encrypted_file = fopen($encrypted_file_name, 'wb');

    stream_filter_append($encrypted_file, 'mcrypt.rijndael_128', STREAM_FILTER_WRITE, $opts);
    //stream_copy_to_stream($my_file, $encrypted_file);

    while (!feof($my_file)) {
        fwrite($encrypted_file, fread($my_file, 4096));
    }

    fclose($encrypted_file);
    fclose($my_file);
    unlink($temp_file);

这是下载代码:

$key = substr(md5('some_salt' . $this->password, true) . md5($this->password . 'more_salt', true), 0, 24);
                $opts = array('iv' => base64_decode($this->iv), 'key' => $key);

                $encrypted_file = fopen($this->file_path, 'rb');
                stream_filter_append($encrypted_file, 'mdecrypt.rijndael_128', STREAM_FILTER_READ, $opts);

                if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
                    header('Content-Type: "application/octet-stream"');
                    header("Content-Disposition: attachment; filename= $this->real_name");
                    header('Expires: 0');
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                    header("Content-Transfer-Encoding: binary");
                    header('Pragma: public');
                    header("Content-Length: " . filesize($this->file_path));
                } else {
                    header('Content-Type: "application/octet-stream"');
                    header("Content-Disposition: attachment; filename= $this->real_name");
                    header("Content-Transfer-Encoding: binary");
                    header('Expires: 0');
                    header('Pragma: no-cache');
                    header("Content-Length: " . filesize($this->file_path));
                }

                fpassthru($encrypted_file);
                fclose($encrypted_file);
                $this->add2Log();
4

1 回答 1

0

如果没有看到一些实际的代码和数据,这很难回答。

然而,作为第一项措施,请使用文本编辑器查看其中一个损坏的 DMG。它可能包含在下载文件期间生成的 PHP 错误消息。这些错误可能发生在所有文件中,但会以其他格式插入。

于 2012-07-27T06:32:32.170 回答