Hi, I have the folowing code for an "Upload file" page...
But i also need to change the destination directory depending on the value of a drop box...
What would be the code to implement this ??
CODE :
<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
<p align="left"><font size="6"> Transfer de fichiers </font></p>
-File:: &&&<input name="userfile" type="file" /><br />
<input type="submit" value="Transfer" />
</form>
<?php
if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {
copy($_FILES["userfile"]["tmp_name"], "files/" . $_FILES["userfile"]["name"]);
echo "<p>Uploaded successfully</p>";
}
?>
Thx for your help !
Dropbox
Moderators: egami, macek, gesf
- Joan Garnet
- Moderator
- Posts: 387
- Joined: Sat Aug 03, 2002 2:56 am
- Location: Mars
- Contact:
I tested it and it works
You should have the directories already created.

Code: Select all
<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="2048000">
<p align="left"><font size="6"> Transfer de fichiers </font></p>
File:<br>
<input name="userfile" type="file" /><br />
Select destination directory<br>
<select name="select">
<option>directory_one</option>
<option>directory_two</option>
<option>directory_three</option>
</select>
<p>
<input type="submit" value="Transfer" />
</form>
<?php
if ($HTTP_POST_VARS){
$dir = $HTTP_POST_VARS["select"];
$filename = $_FILES['userfile']['name'];
if ( !@copy ( $_FILES['userfile']['tmp_name'] , $dir."/".$filename) ){
echo "<b>".$file." </b>couldn't be copied !!<b><br>";
}else{
echo "<b>".$file."</b> has been succesfully copied!<br>";
}
}
?>
You should have the directories already created.