Nolongerused3921 Posted January 13, 2007 Share Posted January 13, 2007 Well I'm trying to get file output through a control script to work, so that I can make sure a user has permissions to view that file... But its just not working - its seeing the file size, its outputing the information, but its just not showing up... Its always an improper image and I'm wondering why....My code:[code=php:0]<?phpob_start();include_once('functions.inc.php');include_once("header.inc.php");if(isset($_GET['id'])) { $id = $_GET['id']; $sql = "SELECT * FROM files WHERE id='$id'"; $result = $mysql->query($sql,"get_file"); $file = $mysql->fetch_row('get_file'); header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Transfer-Encoding: binary"); header("Content-length: $file[size]"); header("Content-type: $file[mime]"); header("Content-Disposition: attachment; filename=$file[name]"); header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); set_time_limit(0); $filename = $exact_dir."/uploaded/".$file[id]."_".$file[name]; $filename = realpath($filename); @readfile($filename); exit;}ob_flush();?>[/code]The file exists and all that as well, heres what size, mime, and name are:Size: 59300Mime: image/pjpegName: 1832-b.jpgWhat could be going wrong here? Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/ Share on other sites More sharing options...
Nolongerused3921 Posted January 14, 2007 Author Share Posted January 14, 2007 Hello? Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160390 Share on other sites More sharing options...
kobmat Posted January 14, 2007 Share Posted January 14, 2007 Can you print_r($file)? All the code seems ok.. im just trying to determine if there is actually data on $file. Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160400 Share on other sites More sharing options...
Nolongerused3921 Posted January 14, 2007 Author Share Posted January 14, 2007 [code] Array( [id] => 7 [name] => 1832-b.jpg [sort_id] => 19 [user_id] => 1 [size] => 59300 [mime] => image/pjpeg [date] => 1168582898)[/code]Weird huh? :( I've even tried taking out the includes, ob_start, and sql stuff and hard code the headers/path myself... Still showing a broken image. Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160401 Share on other sites More sharing options...
kobmat Posted January 14, 2007 Share Posted January 14, 2007 very weird.. data is there.. have also checked on the $filename? if its actually is the right path.can also remove the other headers and just leave content-type, content-length, and disposition? Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160404 Share on other sites More sharing options...
Nolongerused3921 Posted January 14, 2007 Author Share Posted January 14, 2007 Well this kind of sucks... I took out everything and completely rewrote it by hand:[code=php:0] $filename = $exact_dir."/uploaded/7_1832-b.jpg"; $filename = realpath($filename);// header("Pragma: public");// header("Cache-Control: must-revalidate, post-check=0, pre-check=0");// header("Cache-Control: private",false);// header("Content-Transfer-Encoding: binary"); header("Content-length:".filesize($filename)); header("Content-type: image/pjpeg"); header("Content-Disposition: attachment; filename=7_1832-b.jpg");// header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');// set_time_limit(0); @readfile($filename);[/code]And it works... But I can't do this on my actual site, I [b]need[/b] to include the header and functions files, but they have header()s in them... Any ideas? :( Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160408 Share on other sites More sharing options...
kobmat Posted January 14, 2007 Share Posted January 14, 2007 try to uncomment the headers.. one by one.. it should give you an idea what exactly is causing the problem.. right now im thinking its the expires header Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160413 Share on other sites More sharing options...
Nolongerused3921 Posted January 14, 2007 Author Share Posted January 14, 2007 I've already figured it out, its the fact that I'm including functions.inc.php and headers.inc.php, but I [b]need[/b] these two files included... They just call forth sessions, cookies, and I think a header or two... Is there a way to get this to work without unincluding them? Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160414 Share on other sites More sharing options...
kobmat Posted January 14, 2007 Share Posted January 14, 2007 Hmm.. i think calling ob_clean() after the includes will work Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160426 Share on other sites More sharing options...
Nolongerused3921 Posted January 14, 2007 Author Share Posted January 14, 2007 It did :) Thanks a bunch Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160428 Share on other sites More sharing options...
Nolongerused3921 Posted January 14, 2007 Author Share Posted January 14, 2007 Can't seem to edit my post... Oh well - how would I force this to handle the files correctly? Like, show images in the browser, but download videos, songs, etc. - in other words, act how the user's browser would normally act. Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160429 Share on other sites More sharing options...
kobmat Posted January 14, 2007 Share Posted January 14, 2007 You can change the content disposition to inline for images and attachment for other mime types Link to comment https://forums.phpfreaks.com/topic/34044-file-download-not-working/#findComment-160485 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.