note 96297 added to function.readfile
| From: | rajuaryan21 at gmail dot com | Date: | Fri, 19 Feb 2010 10:38:07 +0000 |
| Subject: | note 96297 added to function.readfile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166170@lists.php.net to get a copy of this message | ||
i tried every header attribute referenced here manual n everything goes well n smooth. but wen i m
finished wid the downloading, n try opening the downloaded file (which is a jpeg file) ,it shows
"no preview available".Below is a part of ma code (i have placed here only the code which
is needed for force-downloading):
function downloads ($file) {
ob_start();
$type = end(explode('.',basename($file)));
if(($type =='jpeg') || ($type =='jpg')) {
$type = 'jpeg';
}
if(file_exists($file)) {
header('Expires: 0');
header('Pragma: public');
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
header('Content-Type: image/'.$type);
header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment;filename='.basename($file));
header('Content-Length: ' .filesize($file));
header("Content-Transfer-Encoding: binary\n");
readfile($file);
ob_end_flush();
}
else {
echo "OOPS! Looks like the page might have been removed or deleted. Please consult
Admin for assistance.";
}
after wasting two days of mine, i just came up wid one consequence. i just added one single line
exit; at the end of the if statement. i got the desired result n now everything is much well and
smooth going. Below is mine new blocks of code :
function downloads ($file) {
ob_start();
$type = end(explode('.',basename($file)));
if(($type =='jpeg') || ($type =='jpg')) {
$type = 'jpeg';
}
if(file_exists($file)) {
header('Expires: 0');
header('Pragma: public');
header('Cache-Control: no-cache, must-revalidate, post-check=0, pre-check=0');
header('Content-Type: image/'.$type);
header('Content-Type: application/octet-stream');
header('Content-Description: File Transfer');
header('Content-Disposition: attachment;filename='.basename($file));
header('Content-Length: ' .filesize($file));
header("Content-Transfer-Encoding: binary\n");
readfile($file);
ob_end_flush();
exit;
}
else {
echo "OOPS! Looks like the page might have been removed or deleted. Please consult
Admin for assistance.";
}
but one thing i still can't understand what this exit does. can any genious explain me
dat.Thanks for ur time if u can.
anyway i have posted here since i have waisted mine two days..Hope it would help someone running out
of the same problem...take care, guys n be nice to ur mom.
----
Server IP: 69.147.83.197
Probable Submitter: 123.237.56.83
----
Manual Page -- http://www.php.net/manual/en/function.readfile.php
Edit -- https://master.php.net/note/edit/96297
Del: integrated -- https://master.php.net/note/delete/96297/integrated
Del: useless -- https://master.php.net/note/delete/96297/useless
Del: bad code -- https://master.php.net/note/delete/96297/bad+code
Del: spam -- https://master.php.net/note/delete/96297/spam
Del: non-english -- https://master.php.net/note/delete/96297/non-english
Del: in docs -- https://master.php.net/note/delete/96297/in+docs
Del: other reasons-- https://master.php.net/note/delete/96297
Reject -- https://master.php.net/note/reject/96297
Search -- https://master.php.net/manage/user-notes.php