Its simple striaght, I dont want to actually use any image function, I just want that users CAN view my images, but can not get the actuall image url/address, So its like this, I have the urls of image stored ina database with an id column in front of it. when user opens: display.php?id=187 The database finds that 187 is /images/blabla.jpg The page displays the same image. I searched alot but no use.... Thanks in advance
if your images filename are driven from the database, use a foreign key, with this you can hide your directory..
Hi, The code is simple $imgid = $_GET['id']; $img_location = mysql_fetch_array(mysql_query("SELECT path from imagetable where image_id='{$imgid}'")); $img_location = $img_location[0]['path']; // GETS THE PATH $base_path = 'http://www.url.com/images_base_path'; header("location:{$base_path}/{$img_location}"); PHP: This should redirect the browser to the image file... So if you have this named as image.php... then it will redirect it to the right image. You can add conditions to check if it is proper or not. Thanks imphpguru
That would give away the image's LOCATION to the user, and thats what i want to prevent, anyways thanks for ya all's help but I figured out myself,
hi, great to know that you found it for yourself... it will show the image path only when you go through to view image option. else you can also use file_get_contents something like this... $imgid = $_GET['id']; $img_location = mysql_fetch_array(mysql_query("SELECT path from imagetable where image_id='{$imgid}'")); $img_location = $img_location[0]['path']; // GETS THE PATH $base_path = 'http://www.url.com/images_base_path'; echo file_get_contents("{$base_path}/{$img_location}"); PHP: Hope you find this one exactly matching with what you needed
use that if you don't want SQL injections edit: actually, half of the code is bogus. here's a better version: $imgid = $_GET['id']; list($img_location) = mysql_fetch_array(mysql_query("SELECT path from imagetable where image_id='".intval($imgid)."' LIMIT 1")); if($img_location) { $base_path = 'images_folder'; $ending = substr($img_location,strrpos($img_location,".")+1); header("Content-type: image/".$ending); echo file_get_contents("{$base_path}/{$img_location}"); } else { //display error in image form here maybe? } PHP: whoever wrote the original should be ashamed of themselves. Bad code.