ファイルの帯域幅調整 PHP スクリプトの例へのリンクを次に示します。後で自分で行うこととは無関係ですが、それ以外に改善できることがわかりました...このスクリプトを使用して、帯域幅を制限した画像を返すが、画像を永久にキャッシュする別のスクリプトを作成するにはどうすればよいでしょうか? イメージが変わることはありません。
1 に答える
1
あなたが求めていたのは、そのスクリプトを変更して画像を処理し、コンテンツをキャッシュすることだけだったと思います。これは、私が持っている可能性のある小さなエラーを保留して、それを行う必要があります:
<?php
$file = "yourimage.jpg"; // file to be send to the client
$speed = 8.5; // 8,5 kb/s download rate limit
// if $file is coming from get, I would use this to prevent against a nullbyte attack:
$file = str_replace(chr(0), '', $file);
if (file_exists($file) && is_file($file)) {
header("Expires: ".gmdate('D, d M Y H:i:s', time()+3600*24*3000).'GMT'); // expires in 3000 days.
header("Pragma: cache");
header("Content-Type: image/jpeg"); // needs to be changed for the file type.
header("Content-Length: ".filesize($file));
header("Cache-Control: max-age=" . 3600*24*3000);
flush();
$fd = fopen($file, "r");
while(!feof($fd)) {
echo fread($fd, round($speed*1024));
flush();
sleep(1);
}
fclose ($fd);
}
于 2012-02-16T20:20:52.630 に答える