lopes_andre Posted December 12, 2009 Share Posted December 12, 2009 Hi, I need to get images from outside public_html. I have tested this script, and it works: <?php function getImageFromOutside($filePath, $folder, $file) { if (file_exists($filePath . $folder . $file)) { $contents = file_get_contents($filePath . $folder . $file); return $contents; } } header('Content-type: image/jpeg'); echo getImageFromOutside('C:/xampp/images/', '1/', '1.jpg'); ?> But this script does not do what I want, I need to display images and use HTML Tags, like this: <?php function getImageFromOutside($filePath, $folder, $file) { if (file_exists($filePath . $folder . $file)) { $contents = file_get_contents($filePath . $folder . $file); return $contents; } } header('Content-type: image/jpeg'); echo "<body>"; echo getImageFromOutside('C:/xampp/images/', '1/', '1.jpg'); echo "</body>"; ?> If I use HTML Tags, the image does not show. How can I solve this problem? PS: Sorry for my english. Best Regards. Link to comment https://forums.phpfreaks.com/topic/184919-how-to-get-an-image-from-outside-public-html/ Share on other sites More sharing options...
trq Posted December 12, 2009 Share Posted December 12, 2009 You need to change your first script a little, and place it within a separate file. <?php function getImageFromOutside($filePath, $folder, $file) { if (file_exists($filePath . $folder . $file)) { $contents = file_get_contents($filePath .'/'. $folder .'/'. $file); return $contents; } } header('Content-type: image/jpeg'); $filepath = 'C:/xampp/images/'; $dir = $_GET['d']; $file = $_GET['f']; echo getImageFromOutside('C:/xampp/images/', $dir, $file); ?> Then, whenever you want to use the script you would do so like.... <html> <body> <img src="scriptname.php?d=1$f=1.jpg" /> </body> </html> Link to comment https://forums.phpfreaks.com/topic/184919-how-to-get-an-image-from-outside-public-html/#findComment-976226 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.