steviez Posted September 8, 2009 Share Posted September 8, 2009 Hi, I am making a php image hosting script for my site and i need to get the image to display to the browser on select.. The code will not work and only prints the php file name to the browser??? My Code: <?php /** include common file **/ include $_SERVER['DOCUMENT_ROOT'] . "/includes/common.php"; /** set error var **/ $error = 0; /** get file name and id **/ $image = isset($_GET['filename']) ? mysql_real_escape_string($_GET['filename']) : ''; /** select image info **/ $query = @mysql_query("SELECT * FROM uploads WHERE image_name = '".$image."' LIMIT 1"); $num = @mysql_num_rows($query); $row = @mysql_fetch_array($query); /** does image exist in db? **/ if(!$num) { $error = 1; @header('Content-Type: image/gif'); @header('Content-Disposition: inline; filename=file_not_found.gif'); @readfile('../data/file_not_found.gif'); }else /** does image exist on server? **/ if(!file_exists($_CONFIG['upload']['upload_dir'].$row['image_name'])) { $error = 1; @header('Content-Type: image/gif'); @header('Content-Disposition: inline; filename=file_not_found.gif'); @readfile('../data/file_not_found.gif'); }else /** permissions **/ if($row['image_permissions'] == 'private' && $userid != $row['upload_owner']) { $error = 1; @header('Content-Type: image/gif'); @header('Content-Disposition: inline; filename=access_denied.gif'); @readfile('../data/access_denied.gif'); }else /** no error **/ if($error == 0) { /** get image type **/ $image_type = 'image/' . $row['file_ext']; /** update views **/ @mysql_query("UPDATE uploads SET views = views+1, lastaccess = '".time()."' WHERE id = '".$row['id']."'"); /** update bandwidth useage **/ $used_bandwidth = $row['bandwidth']; $image_bytes = $row['image_size']; $update_bw = $used_bandwidth + $image_bytes; @mysql_query("UPDATE uploads SET bandwidth = '".$update_bw."' WHERE id = '".$row['id']."'"); /** show image **/ @header('Content-Type:' .$image_type); @header('Content-Disposition: inline; filename='.$row['image_name']); @readfile($_CONFIG['upload']['upload_dir'].$row['image_name']); } ?> any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/173478-imagedisplay-help/ Share on other sites More sharing options...
RussellReal Posted September 8, 2009 Share Posted September 8, 2009 You're reading the file's contents to the browser.. which I'm assuming you're outputting the file's contents to be used in an img tag on ANOTHER page.. am I right? it seems like you have a directory attached to the filename.. but if the file is not reading to the browser than it is PROBABLY a mistake on where you stored the file.. or something You might want to send content-length but.. also I see all your updates you probably should do all that in 1 query rather than 4 if it is a .jpg it will not set the correct image type.. it will set image/jpg instead of image/jpeg Quote Link to comment https://forums.phpfreaks.com/topic/173478-imagedisplay-help/#findComment-914492 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.