note 96297 deleted from function.readfile by danbrown

From: Date: Fri, 19 Feb 2010 17:21:01 +0000
Subject: note 96297 deleted from function.readfile by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166182@lists.php.net to get a copy of this message
Note Submitter: rajuaryan21 at gmail dot com ---- 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.

« previous php.notes (#166182) next »