Jump to content

Call to a windows directory


Recommended Posts

 

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

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... :headslap:

Link to comment
Share on other sites

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="" />';

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.