Page 1 of 1

selecting a picture from an online folder

Posted: Sat Jul 21, 2007 4:03 am
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

Posted: Sat Jul 21, 2007 4:44 am
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?

Posted: Sat Jul 21, 2007 6:15 am
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.

Posted: Sat Jul 21, 2007 7:11 am
by feyd
Not possible in the way you wish.

Many systems will use a select box combined with some Javascript to show the image.

Posted: Sat Jul 21, 2007 8:08 am
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?

Posted: Sat Jul 21, 2007 8:26 am
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>';

Posted: Sat Jul 21, 2007 8:29 am
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>';

Posted: Sat Jul 21, 2007 9:27 am
by philc
YES!!!! IT WORKS!!!! heh-heh
thanks alot guys