diablokicks Posted April 26, 2010 Share Posted April 26, 2010 I am extremely new to php and trying to learn by doing. I would like to have a php file that contains variables as images ex: $specialDeals = "images/p7.jpg"; and i would like to be able to call that special deals in another php page. I have googled for 2 hours and have had no luck. <img src="/sockspecials.php?id=specialDeals/" alt="" title="" border="0" /> <!--</a>--> That is what i have in my other page, but i'm getting the red X. Any help would be appreciated. Thank you, Patrick Link to comment https://forums.phpfreaks.com/topic/199812-help-image-as-a-variable/ Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 If you want to use a php file as an image, you need to use a header to change the content type, and grab the contents of the image $file = '/path/to/image/image.jpg'; header('Content-type: image/jpeg'); //Tell the browser it's now an image if(file_exists($file)) //if the file exists in our server { echo file_get_contents($file); //Output the image } You can control the value of $file with $_GET and other things. Link to comment https://forums.phpfreaks.com/topic/199812-help-image-as-a-variable/#findComment-1048837 Share on other sites More sharing options...
diablokicks Posted April 26, 2010 Author Share Posted April 26, 2010 If you want to use a php file as an image, you need to use a header to change the content type, and grab the contents of the image $file = '/path/to/image/image.jpg'; header('Content-type: image/jpeg'); //Tell the browser it's now an image if(file_exists($file)) //if the file exists in our server { echo file_get_contents($file); //Output the image } You can control the value of $file with $_GET and other things. Can you use one PHP file for several images? So having $image1=image2.jpg; $image2=image2.jpg; ... etc What i am trying to do is have 1 php file that i can go to and change the image and have it apply to all of my other pages. Link to comment https://forums.phpfreaks.com/topic/199812-help-image-as-a-variable/#findComment-1048893 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 Whatever you specify $file as, that is the image that will appear. You can change the $file variable manually, or make it change via get variable. So if you have 40 pages linking to image.php with that code, and you changed $file to a different image location, everyone of those pages would then point to the new file. But if you're doing all this manually, why don't you just overwrite the .jpg file? Link to comment https://forums.phpfreaks.com/topic/199812-help-image-as-a-variable/#findComment-1048895 Share on other sites More sharing options...
diablokicks Posted April 26, 2010 Author Share Posted April 26, 2010 On my website it has new product and special product. So every time i want to update those two things i would need to update the image for each page and the link. right? I'm sorry if that doesn't make sense , i'm starting to confuse myself now Link to comment https://forums.phpfreaks.com/topic/199812-help-image-as-a-variable/#findComment-1048932 Share on other sites More sharing options...
de.monkeyz Posted April 26, 2010 Share Posted April 26, 2010 If you had two images say /images/special_product.jpg and /images/product.jpg And those were the only things you were going to change, and manually. All you'd need to do is replace those images with the new image using the same filename, and your pages would use the new image. You only need to use php to generate images if you need something like the image to be random, changed at a certain time, or grabbed from a database. Or in extreme cases, have content generated onto them using GD Link to comment https://forums.phpfreaks.com/topic/199812-help-image-as-a-variable/#findComment-1048933 Share on other sites More sharing options...
diablokicks Posted April 26, 2010 Author Share Posted April 26, 2010 Okay, that makes sense, easiest way to link it then would be to create a special products page and just always have it link to that special product page then. I appreciate your help very much, Thank you again, Patrick Link to comment https://forums.phpfreaks.com/topic/199812-help-image-as-a-variable/#findComment-1048961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.