Uploads Folder, Selected By Select Box? need help!

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
User avatar
JustinMs66
Forum Contributor
Posts: 127
Joined: Sun Sep 03, 2006 4:18 pm

Uploads Folder, Selected By Select Box? need help!

Post 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?
Last edited by JustinMs66 on Sun Sep 10, 2006 1:39 pm, edited 1 time in total.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

You need to make some logic connection between this dropdown and the second argument to move_uploaded_file().
User avatar
JustinMs66
Forum Contributor
Posts: 127
Joined: Sun Sep 03, 2006 4:18 pm

Post by JustinMs66 »

...i don't get it. plz explain more.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
JustinMs66
Forum Contributor
Posts: 127
Joined: Sun Sep 03, 2006 4:18 pm

Post 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.
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post by danharibo »

Code: Select all

$loc = $_GET['loc'];
//procces uploading...
move_uploaded_file($fname,$loc);
User avatar
JustinMs66
Forum Contributor
Posts: 127
Joined: Sun Sep 03, 2006 4:18 pm

Post 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?
danharibo
Forum Commoner
Posts: 76
Joined: Thu Aug 17, 2006 8:56 am

Post 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');
}
User avatar
JustinMs66
Forum Contributor
Posts: 127
Joined: Sun Sep 03, 2006 4:18 pm

Post 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
?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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');
Post Reply