Để tải xuống các tệp lớn từ máy chủ, tôi đã thay đổi các cài đặt dưới đây trong tệp php.ini:
Upload_max_filesize - 1500 M
Max_input_time - 1000
Memory_limit - 640M
Max_execution_time - 1800
Post_max_size - 2000 M
Bây giờ, tôi có thể tải lên và tải xuống video 175MB trên máy chủ.Kể từ đó, tôi có máy chủ chuyên dụng.Vì vậy, thực hiện những thay đổi này là dễ dàng.
Dưới đây là tập lệnh PHP để tải xuống tệp.Tôi không có bất kỳ thay đổi nào trong đoạn mã này cho kích thước tệp lớn.
// Begin writing headers
ob_clean[]; // Clear any previously written headers in the output buffer
if[$filetype=='application/zip']
{
if[ini_get['zlib.output_compression']]
ini_set['zlib.output_compression', 'Off'];
$fp = @fopen[$filepath, 'rb'];
if [strstr[$_SERVER['HTTP_USER_AGENT'], "MSIE"]]
{
header['Content-Type: "$content_type"'];
header['Content-Disposition: attachment; filename="'.$filename.'"'];
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[trim[$filepath]]];
}
else
{
header['Content-Type: "$content_type"'];
header['Content-Disposition: attachment; filename="'.$filename.'"'];
header["Content-Transfer-Encoding: binary"];
header['Expires: 0'];
header['Pragma: no-cache'];
header["Content-Length: ".filesize[trim[$filepath]]];
}
fpassthru[$fp];
fclose[$fp];
}
elseif[$filetype=='audio'|| $filetype=='video']
{
global $mosConfig_absolute_path,$my;
ob_clean[];
header["Pragma: public"];
header['Expires: 0'];
header['Cache-Control: no-store, no-cache, must-revalidate'];
header['Cache-Control: pre-check=0, post-check=0, max-age=0'];
header["Cache-Control: public"];
header["Content-Description: File Transfer"];
header["Content-Type: application/force-download"];
header["Content-Type: $content_type"];
header["Content-Length: ".filesize[trim[$filepath]]];
header["Content-Disposition: attachment; filename=\"$filename\""];
// Force the download
header["Content-Transfer-Encoding: binary"];
@readfile[$filepath];
}
else{ // for all other types of files except zip,audio/video
ob_clean[];
header["Pragma: public"];
header['Expires: 0'];
header['Cache-Control: no-store, no-cache, must-revalidate'];
header['Cache-Control: pre-check=0, post-check=0, max-age=0'];
header["Cache-Control: public"];
header["Content-Description: File Transfer"];
header["Content-Type: $content_type"];
header["Content-Length: ".filesize[trim[$filepath]]];
header["Content-Disposition: attachment; filename=\"$filename\""];
// Force the download
header["Content-Transfer-Encoding: binary"];
@readfile[$filepath];
}
exit;