houssam_ballout Posted July 5, 2011 Share Posted July 5, 2011 Hello all, I had a php script that list content of a folder. I am working with WAMP, the script is at : wamp/www/script well, if I put the images in this folder, it will work perfect, but I need to put the pics in C:\myFolder\pics how can I call that directory from within a php? Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/ Share on other sites More sharing options...
wildteen88 Posted July 5, 2011 Share Posted July 5, 2011 Give the the script the full path to C:\myFolder\pics Example code to list contents of a directory foreach(glob(' C:/myFolder/pics/*') as $file) { echo "$filename size " . filesize($filename) . "\n"; } This will only list the files on the server. You wont be able to list any files from a folder on a users computer. Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/#findComment-1238625 Share on other sites More sharing options...
AyKay47 Posted July 5, 2011 Share Posted July 5, 2011 Hello all, I had a php script that list content of a folder. I am working with WAMP, the script is at : wamp/www/script well, if I put the images in this folder, it will work perfect, but I need to put the pics in C:\myFolder\pics how can I call that directory from within a php? Thanks in advance just like that...either C:\myFolder\pics\file.ext or C:/myFolder/pics/file.ext however, you will not be able to use these paths as an img src..you will need to save them to the server in order use them as an img source Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/#findComment-1238627 Share on other sites More sharing options...
houssam_ballout Posted July 5, 2011 Author Share Posted July 5, 2011 Hello, Well, the path is now C:\MYFolder\SubFolder\Image.jpg I use <img src="PHPVARIBALE-DEFINED TO BE THE PATH" /> but the image won't show Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/#findComment-1238637 Share on other sites More sharing options...
wildteen88 Posted July 5, 2011 Share Posted July 5, 2011 You wont be able to display an image that is outside of the document root (in your case its C:/wamp/www). Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/#findComment-1238639 Share on other sites More sharing options...
xyph Posted July 5, 2011 Share Posted July 5, 2011 <img src="file:///C:/MYFolder/SubFolder/Image.jpg"> Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/#findComment-1238640 Share on other sites More sharing options...
houssam_ballout Posted July 5, 2011 Author Share Posted July 5, 2011 putting file:/// won't work it seems that I need to copy the images from the original folder to the wamp/www/ is there any way to create some global variable to make it work? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/#findComment-1238641 Share on other sites More sharing options...
AyKay47 Posted July 5, 2011 Share Posted July 5, 2011 putting file:/// won't work it seems that I need to copy the images from the original folder to the wamp/www/ is there any way to create some global variable to make it work? Thanks as I have already stated. What are you trying to accomplish exactly? <img src="file:///C:/MYFolder/SubFolder/Image.jpg"> Woah... Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/#findComment-1238648 Share on other sites More sharing options...
Chris92 Posted July 5, 2011 Share Posted July 5, 2011 You could get the file contents and then echo them along with a different header. <?php header('content-type: image/jpg'); echo file_get_contents('C:/MYFolder/SubFolder/Image.jpg'); ?> Or rather than even need to call the php script, base64 encode it and use that as the url (wouldn't recommend either). <?php $image = file_get_contents('C:/MYFolder/SubFolder/Image.jpg'); $base64 = base64_encode($image); echo '<img src="data:image/jpg;base64,'. $base64 .'" alt="" />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/241141-call-to-a-windows-directory/#findComment-1238742 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.