Page 1 of 1

Uploads Folder, Selected By Select Box? need help!

Posted: Sun Sep 10, 2006 3:32 am
by JustinMs66
i have a working uploading script. this is what i want added on:
so i want it so that like if i select "Images" in the select box, it'l upload to "uploads/images/" and if i select "Movies" in the select box, it'l upload to "uploads/movies/"
Image
and like rite now i can get it to always upload to "uploads/images/", but i don't know how to say like:
ok so "dir_pre" is the name of the select box, and "images" is the name of the option.
if($_POST['dir_pre.images'])
and the the rest of the code...followed by "?>"

and then i start a new php code (<?php)
and do the smame thing but:
if($_POST['dir_pre.movies'])

and even if i select movies, it still only uploads to images. help?

Posted: Sun Sep 10, 2006 4:02 am
by bokehman
You need to make some logic connection between this dropdown and the second argument to move_uploaded_file().

Posted: Sun Sep 10, 2006 4:22 am
by JustinMs66
...i don't get it. plz explain more.

Posted: Sun Sep 10, 2006 7:05 am
by bokehman
The second argument is where the file is to be stored. So you need to process your form, take the value of the dropdown, check it for validity and if all is well move the file to that location.

Posted: Sun Sep 10, 2006 1:37 pm
by JustinMs66
i'm not THAT good at PHP to know what u are talking about.
and i already have a whole bunch of code that i want...
so what would help if you could do:

<?php
if the directory is "Movies"
//i'l put my code here
and
if the directory is "Images"
//i'l put my code here
and
if the directory is "Music"
//i'l put my code here
?>

and like tell me where i can insert my code... that would be a big help.

Posted: Sun Sep 10, 2006 1:42 pm
by danharibo

Code: Select all

$loc = $_GET['loc'];
//procces uploading...
move_uploaded_file($fname,$loc);

Posted: Sun Sep 10, 2006 1:51 pm
by JustinMs66
what is "loc" and what does it do?

because since i'm gunna want more than 1 folder, how does it know like which one? or do i replace 'loc' with 'images' ???

and if i want more than 1 folder, would i just do:

Code: Select all

<?php
$loc = $_GET['images'];
//procces uploading...
move_uploaded_file($fname,$loc); 

$loc = $_GET['music'];
//procces uploading...
move_uploaded_file($fname,$loc); 

$loc = $_GET['movies'];
//procces uploading...
move_uploaded_file($fname,$loc); 
?>
and would that work?

Posted: Sun Sep 10, 2006 1:54 pm
by danharibo
no no no, You do it like this:
loc is the name of the Dropdown box and it goes like this:
?loc=music
so it would upload to /music or you could try this:
procupload.php?loc=2

Code: Select all

if(loc = 2)
{
move_uploaded_file($fname,'/music');
}

Posted: Sun Sep 10, 2006 4:07 pm
by JustinMs66
...ok, but again, if i wanted to put my own code in there, would i do this?

Code: Select all

if(loc = 2)
{
move_uploaded_file($fname,'/music');
}
//my code goes here
and what about having 3 different folders in terms of the code, would i just do this?

Code: Select all

if(loc = 2)
{
move_uploaded_file($fname,'/music');
}
//my code goes here

if(loc = 3)
{
move_uploaded_file($fname,'/Movies');
}
//my code goes here
?

Posted: Sun Sep 10, 2006 4:29 pm
by volka
I would use some kind of mapping for both, printing the select element and evaluating the path from the selected element.
Simple example

Code: Select all

$paths = array(1=>'music', 2=>'movies', 3=>'audiobooks');