Current location: Hot Scripts Forums » Programming Languages » PHP » Upload to user-defined directory?


Upload to user-defined directory?

Reply
  #1 (permalink)  
Old 09-26-03, 11:10 AM
tom tom is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Upload to user-defined directory?

hey guys,
i have a working uploader running on my site, which is all very nice, but nowi want to categorise my index of files.

i'm gonna do it in like 5 folders.. photography / paintings / sketches etc.

i want to be able to upload any type of file to my server, but i want it to upload to the correct directory.

suppose i am viewing my photography directory, and i want to add a new photo. i want to click the link to this uploader script, and then upload the file, but also upload it into the apropriate directory.
if my file was called "photo_12.jpg", this is how it currently works out.

/photography/
/sketches/
/paintings/
/photo_12.jpg

but i want that to be

/photography/photo_12.jpg
/sketches/
/paintings/

i am not much of a coder, i got the original upload script from somewhere else. what i would like to know is, how do i expand the current solution to work with multiple directories? i'd like there to be a dropdown menu or something, maybe a radiop button or whatever, to allow me to tell the script where i want the file to land.

i'll post the uploader code in a second
Reply With Quote
  #2 (permalink)  
Old 09-26-03, 11:14 AM
tom tom is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
here is that code!

upload.php
PHP Code:

<?php


require("upload_config.php");

if(
$doupload) {

if(
$ADMIN[RequirePass] == "Yes") {
if(
$password != "$ADMIN[Password]") {
?>
    <p />&nbsp;&nbsp;
    <strong>
    <font color="#FF0000" face="Verdana">Error</font>
    </strong>


  <table width="450" border="0" cellspacing="0"
cellpadding="0">
    <tr> 
      <td width="450">
          <table width="450" border="0" cellspacing="1" cellpadding="2">
            <tr> 
              <td colspan="2">Invalid password.</td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</P>
</body>
</html>
<?php
exit();
}
}

$num 0;
while(
$num $ADMIN[UploadNum]) {
$num++;


$picture "fileup$num"."_name";
$picture1 = $$picture;
$picture2 "fileup$num";
$picture3 = $$picture2;

if(
$picture3 != "none") {
$filesizebtyes filesize($picture3);

$ok 1;
if(
$filesizebtyes 10) {
$error .= "Error uploading (file size lower than 10 bytes) for file $num<BR>";
$ok 2;
}



if(
file_exists("$ADMIN[directory]/$picture1") OR $ok == 2) {
$error .="File name already exists for file $num<BR>";
} else {
copy ($picture3"$ADMIN[directory]/$picture1");
$error .="File $num has been uploaded<BR>";
}
}
}

if(!
$error) {
$error .= "No files have been selected for upload";
}


?>
<p />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b>Status</b>


<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<table width="450" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td width="100%"> <table width="450" border="0" cellspacing="1" cellpadding="2">
          <tr> 
            <td colspan="2"><?php echo $error?></td>
          </tr>
        </table></td>
    </tr>
  </table>
  </body>
</P>
</BODY>
</html>
<?php
exit();

} else {

$num 0;
while(
$num $ADMIN[UploadNum]) {
$num++;
$html .= "
<TR>
        <TD WIDTH=\"30%\" class=\"topBlue\"><strong>File:</strong></TD> 
        <TD WIDTH=\"70%\">
        <INPUT NAME=\"fileup
$num\" TYPE=\"file\" SIZE=\"25\">
</TD> "
;
}

?>
<form enctype="multipart/form-data" action="upload.php" method="post">
<strong>Upload</strong>

  
    <table border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td>
            <table width="400" border="0" cellspacing="1" cellpadding="2">
            <?php echo $html?> </table></td>
      </tr>
    </table>
  </P>
  <?php
if($ADMIN[RequirePass] == "Yes") {
?>
  <p></p>
  
    <table border="0" cellspacing="0" cellpadding="0">
      <tr> 
        <td> 
        <table width="400" border="0" cellspacing="1" cellpadding="2">
            <tr> 
              
          <td width="30%"> <span class="topBlue"><strong>Password:</strong></span><strong></font></strong></td>
              <td width="70%"> <input name="password" type="password" size="25" /> 
              </td>
            </tr>
          </table></td>
      </tr>
    </table>
  </P>
  <?php
}
?>
  <p>
    
      <input name="doupload" type="submit" value="Upload Files" />
    
  </p>
</form>



</BODY>
</HTML> 
<?php
exit();
}


?>
upload_config.php
PHP Code:

<?php


$ADMIN
[RequirePass] = "Yes";   // Checks to see if upload has a vaild password
$ADMIN[Password] = "tom";   // This is the password if the above option is Yes
$ADMIN[UploadNum] = "1";  // Number of upload feilds to put on the html page
$ADMIN[directory] = "root";  // The directory the files will be uploaded to (must be chmoded to 777)

?>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
user management and searching.. alvibd Script Requests 1 09-27-03 12:53 PM
Ad management and optimisation using php surebetdmg PHP 0 08-28-03 06:45 PM
Showing images in a directory Bob PHP 4 08-25-03 08:16 AM
Registration Script with file upload rcrane Script Requests 1 08-12-03 12:05 PM
send mail to user onlynils New Members & Introductions 1 07-04-03 01:18 PM


All times are GMT -5. The time now is 06:19 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.