immobilarity Posted August 14, 2007 Share Posted August 14, 2007 I'm new to PHP and am hoping someone can help me with a problem. I have a page named printdocs.php that needs to include multiple .html pages into one page for printing purposes. The printdocs.php page looks like this: include('documents/100/100.html'); include('documents/101/101.html'); include('documents/102/102.html'); Each one of the .html files I'm trying to include has relative references to images (i.e. 100.html has <img src="100-101.jpg" />). When I use the above include functions, the html outputs properly but the images do not display. Note: I cannot change the code in the included .html files. Is there a way to get the images to display? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/64905-include-subdirectory-images-not-displaying/ Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 The links to the images are relative to the folder that the html file is in. The fact that they are all in different folders means that you change the link of the image to wherever your php file is. The only way to could change the links on the html after including them is to read the contents into a buffer and search for the image links and change them. Other than that, you could move all the html files to the same folder as the php along with the images. Quote Link to comment https://forums.phpfreaks.com/topic/64905-include-subdirectory-images-not-displaying/#findComment-323812 Share on other sites More sharing options...
ViN86 Posted August 14, 2007 Share Posted August 14, 2007 when you reference files, you need to reference them as if they were being loaded for the page the code is included into. so if youre in the /htdocs directory and you include a file in the /htdocs/includes directory, then the file needs to call the images as if it were in the /htdocs directory. you can use PHP to create a dynamic link that calls the image location based on where the file is being called. Quote Link to comment https://forums.phpfreaks.com/topic/64905-include-subdirectory-images-not-displaying/#findComment-323814 Share on other sites More sharing options...
immobilarity Posted August 14, 2007 Author Share Posted August 14, 2007 Other than that, you could move all the html files to the same folder as the php along with the images. I wish I could do that but these documents get updated almost on a daily basis and must remain within the documents subdirectory. I use to program in ColdFusion and including files like this was not a problem (images would display)...so I'm a little stumped as to why I couldn't do the same with PHP. I can change the images src from "100-101.jpg" to "documents/100/100-101.jpg" via javascript but i was hoping there'd be something simple with PHP. Thanks for the quick reply. Quote Link to comment https://forums.phpfreaks.com/topic/64905-include-subdirectory-images-not-displaying/#findComment-323833 Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 You could use something like echo ereg_replace("<img src=\"", "<img src=\"documents/100/", file_get_contents("documents/100/100.html")); That is assuming all the image tags are written like that (which is probable.) And actually, using file_get_contents() is a little more efficient than include() when you aren't using any php in the file Quote Link to comment https://forums.phpfreaks.com/topic/64905-include-subdirectory-images-not-displaying/#findComment-323841 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.