Ben bir resim $ dosyası var (örn. .. / resim.jpg)
mime tipi $ türü olan
Tarayıcıya Nasıl ben çıkış olabilir?
Eğer web sunucusu kendiniz yapılandırmak için özgürlük varsa, mod_xsendfile (Apache için) gibi araçlar okuma ve PHP dosyayı yazdırırken çok daha iyidir. PHP kodu aşağıdaki gibi olacaktır:
header("Content-type: $type");
header("X-Sendfile: $file"); # make sure $file is the full path, not relative
exit();
mod_xsendfile X-SendFile başlığını alır ve kendisi tarayıcı dosyayı gönderir. Bu, özellikle büyük dosyaları için, performans gerçek bir fark yaratabilir. Önerilen çözümlerin çoğu belleğe tüm dosyayı okumak ve daha sonra yazdırabilirsiniz. Bu bir 20kbyte görüntü dosyası için Tamam, ama 200 MByte TIFF dosyası varsa, sorun olsun uğrarsınız.
$file = '../image.jpg';
if (file_exists($file))
{
$size = getimagesize($file);
$fp = fopen($file, 'rb');
if ($size and $fp)
{
// Optional never cache
// header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
// header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
// header('Pragma: no-cache');
// Optional cache if not changed
// header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($file)).' GMT');
// Optional send not modified
// if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) and
// filemtime($file) == strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']))
// {
// header('HTTP/1.1 304 Not Modified');
// }
header('Content-Type: '.$size['mime']);
header('Content-Length: '.filesize($file));
fpassthru($fp);
exit;
}
}
Sen header sağ Content-type göndermek için kullanabilirsiniz:
header('Content-Type: ' . $type);
Ve readfile
a> çıkış görüntünün içeriği:
readfile($file);
And maybe (probably not necessary, but, just in case) you'll have to send the Content-Length header too :
header('Content-Length: ' . filesize($file));
Note : make sure you don't output anything else than your image data (no white space, for instance), or it will no longer be a valid image.