我无法从我的在线商店提供 .dmg。我将代码精简为以下内容以进行调试,但无论我得到一个零字节文件是什么:
header('Content-Type: application/x-apple-diskimage'); // also tried octet-stream
header('Content-Disposition: attachment; filename="My Cool Image.dmg"');
$size = filesize('/var/www/mypath/My Cool Image.dmg');
header('Content-Length: '.$size);
readfile('/var/www/mypath/My Cool Image.dmg');
同样的代码适用于我提供的许多其他文件类型:bin、zip、pdf。有什么建议么? Google 教授不是我的 friend 。
最佳答案
找到解决方案。罪魁祸首是 readfile() 并且可能与内存有关。代替 readfile() 行,我使用这个:
$fd = fopen ('/var/www/mypath/My Cool Image.dmg', "r");
while(!feof($fd)) {
set_time_limit(30);
echo fread($fd, 4096);
flush();
}
fclose ($fd);
它现在可以正确处理所有文件类型,包括 DMG。
关于php - 如何通过 PHP/readfile 提供 .dmg 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10327135/