Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Dropbox

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Dropbox

Postby border20 » Wed Jan 29, 2003 10:16 am

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 !
border20
New php-forum User
New php-forum User
 
Posts: 32
Joined: Tue Jan 28, 2003 10:19 am
Location: Québec

Postby Joan Garnet » Wed Jan 29, 2003 5:09 pm

I tested it and it works :)
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.
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron