Jump to content

Archived

This topic is now archived and is closed to further replies.

JustinMs66@hotmail.com

Uploads Folder, Selected By Select Box? need help!

Recommended Posts

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/"
[img]http://www.csscobalt.com/33/uploads/cats/images/help_php_v02.JPG[/img]
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.[b]movies[/b]'])

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

Share this post


Link to post
Share on other sites
do you mean you want to give the dropdown a if condition.
[code]
<?php

if($uploads=="movie"){

do somethink

}elseif($uploads=="images"){

do somethink

}
?>
[/code]

good luck.

Share this post


Link to post
Share on other sites
and if i wanted more than 2 folders, would i just do this?

[code]<?php
if($uploads=="movies"){
do somethink
}elseif($uploads=="images"){
do somethink
}elseif($uploads=="Music"){
do somethink
}
?>[/code]

and wouldn't it be:
if($_POST['dir_pre.movies']){
instead of:
if($uploads=="movies"){

Share this post


Link to post
Share on other sites
example not tested yet!

uplaods was the name of the select name="uplaods" within the select box i had images and movie

[code]
<?php


$folder1="redarrow_movie";
$folder2="justin_movie";

$folder3="redarrow_images";
$folder4="justin_images";

if($uploads=="movie"){

mkdir($folder1);
mkdir($folder2);

}elseif($uploads=="images"){

mkdir($folder3);
mkdir($folder4);
}
?>
[/code]

Share this post


Link to post
Share on other sites
try
[code]<?php
if (isset($_POST['dir_pre'])) {

    $dir_pre = $_POST['dir_pre'];

    $upload_dir = "uploads/$dir_pre/";

    echo $upload_dir;
}

?>
<FORM method='POST'>
<select name="dir_pre">
  <option value="movies">Movies</option>
  <option value="images">Images</option>
</select>
<input type="submit" name="submit" value="Submit">[/code]

Share this post


Link to post
Share on other sites
Then just add another option to the select

<option value="music">Music</option>

Share this post


Link to post
Share on other sites
So did I. The PHP code stays the same.

Run my original snippet, then add the extra music option and run it again

Share this post


Link to post
Share on other sites
it does what I thought you were asking it to do

If user selects "Movies" set the upload folder to "uploads/movies"
If user select "Images" set the upload folder to "uploads/images"
If user select "Music" set the upload folder to "uploads/music"

Share this post


Link to post
Share on other sites
Here is a nice code for you to see how to make a dir with a dropdown box, Also show the dir that have been made from the mkdir.

your notice  in this code i have used @ to stop errors if the dir is empty.

all you goto do is make a folder called  pu .

good luck.

test.php
[code]
<?php

if($_POST['submit']){

$folder="up";

$folder1="$folder/redarrow_movie";

$folder2="$folder/justin_movie";

$folder3="$folder/redarrow_images";

$folder4="$folder/justin_images";

if($uploads=="movie"){

mkdir($folder1);
mkdir($folder2);

}elseif($uploads=="images"){

mkdir($folder3);
mkdir($folder4);
}
  }

$dirpath = $folder;

$dlist = @opendir($dirpath);

echo "<table align='center' border='4' boredcolor='black'>
<td align='center'><br><b>This is the folders that you own</b><br>";

$info = "<select name='dir'>";

while ($read = @readdir($dlist)) {

$info.="<option value='$read'>$read</option>";

}
@closedir($dlist);

$info.="</select>";

echo $info;

?>

<form method="POST" action="">

<br>

<b>Please choose a dir to upload to</b>

<br>

<select name="uploads">

<option value="movie">movie</option>

<br>

<option value="images">images</option>

<br>

</select>

<br>

<br>

<input type="submit" name="submit" value="Make!">

</form>

</td>

</table>
[/code]

Share this post


Link to post
Share on other sites
wul i already have a whole bunch of code that i want...
so what would help if you could do:

[color=red]<?php[/color]
[color=green]if [/color]the directory is "Movies"
[color=orange]//i'l put my code here[/color]
and
[color=green]if [/color]the directory is "Images"
[color=orange]//i'l put my code here[/color]
and
[color=green]if[/color] the directory is "Music"
[color=orange]//i'l put my code here[/color]
[color=red]?>[/color]

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

Share this post


Link to post
Share on other sites

×

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.