我创建了一个上传网站,出于某种原因处理.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();
答案 0 :(得分:0)
如果没有看到一些实际的代码和数据,这很难回答。
然而,作为第一个衡量标准,请使用文本编辑器查看其中一个损坏的DMG。它可能包含在下载文件期间生成的PHP错误消息。这些错误可能发生在所有文件中,但是以其他格式插入。