我刚刚从 000webhost(免费)切换到 godaddy(付费)服务器,到目前为止,它比 000webhost 差 10 倍 >.>
无论如何,我的问题在于下载。我使用以下代码,它在 000webhost 上运行良好,允许用户下载 rar 文件,但现在在 godaddy 上,rar 文件将返回存档错误结束。我通过 FTP 检查,文件没有通过上传损坏
<?php
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$IP1 = $_SERVER['HTTP_X_FORWARDED_FOR'];
$IP2 = $_SERVER['REMOTE_ADDR'];
$HWID = $_GET['HWID'];
date_default_timezone_set('America/New_York');
$date = date("m/d/y g:i:sA", time());
$file = $_GET['file'];
file_put_contents('Logs/Downloaded.txt', "IP: " . $IP2 . " Downloaded On: " . $date . " File: " . $file . " User Agent: " . $userAgent . "\n", FILE_APPEND);
$path = "files/";
$fullPath = $path.$file;
if(file_exists($fullPath)){
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
break;
case "zip":
header("Content-type: application/zip");
break;
default;
header("Content-type: application/octet-stream");
}
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
ob_flush();
flush();
}
}
fclose ($fd);
exit;
}else{
die("File could not be found");
}
?>