selecting a picture from an online folder

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
philc
Forum Newbie
Posts: 9
Joined: Sat Jul 21, 2007 3:48 am

selecting a picture from an online folder

Post by philc »

hi,

I'm new to php, I've been trying to search for my problem long but most probably i'm not searching under the right criteria.

I have a folder on my website, and i would like to choose a picture from it from a file input tag. "<input type="file" name="flower_picture" />"

every time i click on the browse button it shows computer files (that's normal), but can I instead view pictures from my website from the folder pictures/flowers/ ?

thanks in advance, if I need to post more info please feel free to ask, i'm new so I have to learn :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The file is already stored on the webserver but you want to be able to upload it again via input/file? Can you please elucidate?
philc
Forum Newbie
Posts: 9
Joined: Sat Jul 21, 2007 3:48 am

Post by philc »

I would like to select the uploaded picture from the folder pictures/flowers/ so it stores the name of the picture in mysql table. but when I click browse I would like to see the online picture that are in the folder flowers. it does not have to be an input file tag, anything would do but I don't know how and i would like to know if there are any options.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Not possible in the way you wish.

Many systems will use a select box combined with some Javascript to show the image.
philc
Forum Newbie
Posts: 9
Joined: Sat Jul 21, 2007 3:48 am

Post by philc »

well i dont want to see the images whats in the folder but the filenames of the pictures and select one. is there a way?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe something like

Code: Select all

$path = 'pictures/flowers/';
echo '<select name="xyz">';
foreach(glob($path.'*') as $e) {
	echo '<option>', htmlentities(basename($e)), "</option>\n";
}
echo '</select>';
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

A quick and dirty solution:

Code: Select all

$files = array();
if($handle = opendir('/path/to/files'))
{
    while ((false !== ($file = readdir($handle))) && ($file != '.') && ($file != '..'))
    {
        $files[] = $file;
    }

    closedir($handle);
}

echo '<select name="image_select">';

foreach($files AS $file)
{
    echo '<option value="' . $file . '">' . $file . '</option>';
}

echo '</select>';
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
philc
Forum Newbie
Posts: 9
Joined: Sat Jul 21, 2007 3:48 am

Post by philc »

YES!!!! IT WORKS!!!! heh-heh
thanks alot guys
Post Reply