+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: User Uploader

  1. #1
    evilchinesefood is offline x10Hosting Member evilchinesefood is an unknown quantity at this point
    Join Date
    Jul 2005
    Posts
    31

    User Uploader

    Ok here is my code. I want it when you upload it, it uploads it to

    http://www.darkware.x10hosting.com/downloads

    Also you know on the cpanel when you first get to it. It ask youy for password and screenname caqn you add something like that too.

    PHP Code:
     <html dir="ltr">
        <
    head>
            <
    title>Darkware File Uploader 1.0</title>
            <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1;" />
            <
    meta name="description" content="Darkware File Uploader" />
            <
    meta name="keywords" content="PHP, upload, free, open, source, SFU, simple, simplicity" />
            <
    style type="text/css">
            <!--
            
    body {
               
    font-familyTahomaverdanafont-size12px;
            }
            
    p.header {
               
    font-size18px;
            }
               
    a:linka:visited {
               
    color#009999; text-decoration:none;
            
    }
            
    a:active {
                
    color#FF6600; text-decoration:none;
            
    }
            
    td {
                
    font-size:12px;
            }
            
    td.note {
                
    font-size:10px;
            }
             -->
            </
    style>
        </
    head>
      <
    body>
     <
    p align="center" class="header">Darkware File Uploader 1.0</p><table width="20%" border="0" align="center" style="border-collapse: collapse;">
       <
    tr>
          <
    td width="100%" align="center">
                <
    form method="post" enctype="multipart/form-data" action="/files/upload.php">
                <
    input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
                <
    input type="file" name="SFUfile[]" size="20" /><br /></td>
       </
    tr>
       <
    tr></br>
          <
    td width="100%" align="left">
            <
    span style="font-size: 7pt; font-family: tahoma, verdana;"><b>Size Limit</b>: 10.00 MB<br />
       <
    b>Allowed Extensions</b>: All types alowed for now. <br /></span></td>
       </
    tr>
       <
    tr>
          <
    td align="center">
    </
    br>
          <
    span style="font-size: 7pt; font-family: tahoma, verdana;">Powered By: <a href="http://www.darkware.uni.cc" target="_blank">&copyDarkware 2004 2005. All rights reserved.</a></span><br />
            <
    input type="submit" value="  Upload  " name="SFUsubmit" /></td>
       </
    tr>
        </
    form>
    </
    table>
             
            </
    span></p>
        </
    body>
    </
    html
    Last edited by evilchinesefood; 08-02-2005 at 06:26 PM.

  2. #2
    Bryon is offline Administrator Bryon has disabled reputation
    Join Date
    Apr 2005
    Location
    Northfield, NH
    Posts
    7,608

    Re: User Uploader

    All you have is the easy HTML side.... I don't want to code all that for you... Find a tutorial somewheres on how to do that. I'm pretty sure that's what your asking, even though you dont come out and say it. Sorry, but I'm not going to... someone else can if they want.

  3. #3
    evilchinesefood is offline x10Hosting Member evilchinesefood is an unknown quantity at this point
    Join Date
    Jul 2005
    Posts
    31

    Re: User Uploader

    ok i got this. Now what do i do with it? Were do i add it in and what do i need to change on it so it will work.

    PHP Code:
     <? 
    //uses $_FILES[] global array 
    //see manual for older PHP version info 
    //This function will be used to get the extension from the filename 
    function get_extension($file,$length=-1){ 
    $p strrpos($file,"."); 
    $p++; 
    if(
    $length!=-1){ 
      
    $ext substr($file,$p,$length); 

    if(
    $length==-1){ 
      
    $ext substr($file,$p); 

    $ext strtolower($ext); 
    return 
    $ext

    //Not good practice, but here anyway 
    //change to suit your needs 
    //2meg max 
    ini_set("upload_max_filesize","2M"); 
    //turn on file uploads 
    ini_set("file_uploads","1"); 
    //set your temp dir 
    ini_set("upload_tmp_dir","/tmp"); 
    //set post size large enough to accomidate 
    //3 2meg files and some overhead 
    ini_set("post_max_size","8M"); 
    ?> 
    <html> 
    <head> 
      <title>ftp connect and upload</title> 
    </head> 
    <body> 
    <? 
    //check to see if we have submited yet 
    if($_POST["submit"]!="submit"){ 
    //not yet so lets make the form 
    ?> 
    <p><center>Upload Files to ftp site (10M MAX)</center></p> 
    <p> 
    <form name="fileup" method="post" enctype="multipart/form-data" action="<? echo $PHP_SELF?>"> 
    <input type="file" name="userfiles[]"><br> 
    <input type="file" name="userfiles[]"><br> 
    <input type="file" name="userfiles[]"><br> 
    <br> 
    <!-- change below to your max --> 
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000"> 
    <input type="submit" value="submit" name="submit"> 
    </form> 
    </p> 
    <? 

    //see if we have submited and that the files array has been set 
    if(($_POST["submit"]=="submit")&&(is_array($_FILES['userfiles']))){ 
    $ftp_user_name="ftpuser"//change to ftp username 
    $ftp_user_pass="ftppass"//change to ftp password 
    $ftp_server="/home/darkware/public_ftp/upload.php"//change to ftp url 
    $ftp_dump_dir="/downloads"//change to destination directory 
    //go through all the files 
    for($x=0;$x<count($_FILES['userfiles']['name']);$x++){ 
      
    //now we do some file checking 
      //check to see if file it there 
      
    if($_FILES['userfiles']['name'][$x]!="none"){ 
      
    //file has a name 
      //check filesize 
          
    if($_FILES['userfiles']['size'][$x]!=0){ 
            
    //file is larger than 0 bytes 
              //Check to see if it is uploaded 
              
    if(is_uploaded_file($_FILES['userfiles']['tmp_name'][$x])){ 
                   
    //file has been uploaded! 
                 //let the user know their file has be uploaded 
                 
    echo "file ".$_FILES['userfiles']['name'][$x]." uploaded!<br>"
                 
    //conect to ftp server 
                 
    $conn_id ftp_connect($ftp_server); 
                
    // login with username and password 
                  
    $login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass); 
                
    // check connection 
                 
    if ((!$conn_id) || (!$login_result)) { 
                  echo 
    "FTP connection has failed!<br>"
                  echo 
    "Attempted to connect to $ftp_server for user $ftp_user_name"
                  exit; 
                } else { 
                     echo 
    "Connected to $ftp_server! <br>"
                     
    //set PASV mode 
                     
    if(!ftp_pasv($conn_id,TRUE)){ 
                         echo 
    "Could not enter PASV mode!"
                     } 
                     
    //rename to file#_date.ext 
                     
    $filename "file".($x+1)."_".date("MdY"); 
                     
    $filename.= ".".get_extension($_FILES['userfiles']['name'][$x],3); 
                     
    //change directory 
                     
    if (@ftp_chdir($conn_id$ftp_dump_dir)) { 
                         
    //maybe you want to make sure we are in the correct directory 
                        
    echo "Current directory is now : "ftp_pwd($conn_id), "\n"
                    } else { 
                      
    //you want to know if it didn't work 
                      
    echo "Couldn't change directory\n"
                    } 
                      
    //upload the file and let the user know what happened 
                    
    if(ftp_put($conn_id,$filename,$_FILES['userfiles']['tmp_name'][$x],FTP_BINARY)){ 
                           echo 
    "File ".$_FILES['userfiles']['name'][$x]." was sent successfully<br>"
                        echo 
    "File was named ".$filename."<br>"
                    }else{ 
                           echo 
    "There was a problem sending file ".$_FILES['userfiles']['name'][$x]."<br>";; 
                             } 
                    } 
                    
    // close the FTP stream 
                    
    ftp_close($conn_id); 
                } 
                else echo
    "File was not uploaded!<br>"
            } 
        } 
        echo 
    "<br>"
    }
    //end for loop 

    //That's all folks! 
    ?> 
    </body> 
    </html>
    Last edited by evilchinesefood; 08-02-2005 at 11:57 PM.

  4. #4
    03moscropl's Avatar
    03moscropl is offline Flash Freak 03moscropl is an unknown quantity at this point
    Join Date
    Jun 2005
    Location
    England
    Posts
    349

    Re: User Uploader

    there is and easeir way that does all the work for you it is frantisco and is php forms genorator that makes up to 100 different forms like uploaders!
    my customised games module for phpnuke
    http://dragongamer.net/modules.php?name=arcade

  5. #5
    Bryon is offline Administrator Bryon has disabled reputation
    Join Date
    Apr 2005
    Location
    Northfield, NH
    Posts
    7,608

    Re: User Uploader

    Or, he could learn how to do it himself, which is much much better.


    I believe that you could use that entire second "script" that you just posted as the entire thing. It looks as if it has it all right in it. Let me try it out and see.

    Edit: It's messed up and doesn't work right, and I don't have the time to fix it right now.

    I found this link: http://www.samspublishing.com/articl...29587&seqNum=9

    Try and see if you could use that...
    Last edited by Bryon; 08-03-2005 at 11:08 AM.

  6. #6
    evilchinesefood is offline x10Hosting Member evilchinesefood is an unknown quantity at this point
    Join Date
    Jul 2005
    Posts
    31

    Re: User Uploader

    ok whats wrong with this. It works but i cant seem to download the file?

    PHP Code:
     <html>
     <head>
     <title>Listing 9.14 A file upload script</title>
     </head>
     <?php
     $file_dir 
    "/downloads/";
     
    $file_url "http://www.darkware.x10hosting.com/downloads/";
     
     foreach( 
    $HTTP_POST_FILES as $file_name => $file_array ) {
       print 
    "path: ".$file_array['tmp_name']."<br>\n";
       print 
    "name: ".$file_array['name']."<br>\n";
       print 
    "type: ".$file_array['type']."<br>\n";
       print 
    "size: ".$file_array['size']."<br>\n";
     
       if ( 
    is_uploaded_file$file_array['tmp_name'] ) 
         && 
    $file_array['type'] == "image/gif" ) {
         
    move_uploaded_file$file_array['tmp_name'], "$file_dir/$file_name"
           or die (
    "Couldn't copy");
         print 
    "<img src=\"$file_url/$file_name\"><p>\n\n";
      }
    }
     
     
    ?>
     <body>
     <form enctype="multipart/form-data" method="POST">
     <input type="hidden" name="MAX_FILE_SIZE" value="10000000">
    <input type="file" name="fupload"><br>
    <input type="submit" value="Upload">
     </form>
     </body>
     </html>

  7. #7
    Bryon is offline Administrator Bryon has disabled reputation
    Join Date
    Apr 2005
    Location
    Northfield, NH
    Posts
    7,608

    Re: User Uploader

    Ill look into it quick. Ill edit this when Im done.

    Edit: Ok, I could not get that work. BUT, I have found a nice one to use on php.net. Here's the code:


    PHP Code:

    <?
    function uploader($num_of_uploads=1$file_types_array=array("txt","gif","jpeg"), $max_file_size=1048576$upload_dir="downloads/"){
      if(!
    is_numeric($max_file_size)){
       
    $max_file_size 1048576;
      }
      if(!isset(
    $_POST["submitted"])){
       
    $form "<form action='".$PHP_SELF."' method='post' enctype='multipart/form-data'>Upload files:<br /><input type='hidden' name='submitted' value='TRUE' id='".time()."'><input type='hidden' name='MAX_FILE_SIZE' value='".$max_file_size."'>";
       for(
    $x=0;$x<$num_of_uploads;$x++){
         
    $form .= "<input type='file' name='file[]'><font color='red'>*</font><br />";
       }
       
    $form .= "<input type='submit' value='Upload'><br /><font color='red'>*</font>Maximum file length (minus extension) is 15 characters. Anything over that will be cut to only 15 characters. Valid file type(s): ";
       for(
    $x=0;$x<count($file_types_array);$x++){
         if(
    $x<count($file_types_array)-1){
           
    $form .= $file_types_array[$x].", ";
         }else{
           
    $form .= $file_types_array[$x].".";
         }
       }
       
    $form .= "</form>";
       echo(
    $form);
      }else{
       foreach(
    $_FILES["file"]["error"] as $key => $value){
         if(
    $_FILES["file"]["name"][$key]!=""){
           if(
    $value==UPLOAD_ERR_OK){
             
    $origfilename $_FILES["file"]["name"][$key];
             
    $filename explode("."$_FILES["file"]["name"][$key]);
             
    $filenameext $filename[count($filename)-1];
             unset(
    $filename[count($filename)-1]);
             
    $filename implode("."$filename);
             
    $filename substr($filename015).".".$filenameext;
             
    $file_ext_allow FALSE;
             for(
    $x=0;$x<count($file_types_array);$x++){
               if(
    $filenameext==$file_types_array[$x]){
                 
    $file_ext_allow TRUE;
               }
             }
             if(
    $file_ext_allow){
               if(
    $_FILES["file"]["size"][$key]<$max_file_size){
                 if(
    move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename)){
                   echo(
    "File uploaded successfully. - <a href='".$upload_dir.$filename."' target='_blank'>".$filename."</a><br />");
                 }else{
                   echo(
    $origfilename." was not successfully uploaded<br />");
                 }
               }else{
                 echo(
    $origfilename." was too big, not uploaded<br />");
               }
             }else{
               echo(
    $origfilename." had an invalid file extension, not uploaded<br />");
             }
           }else{
             echo(
    $origfilename." was not successfully uploaded<br />");
           }
         }
       }
      }
    }

    echo 
    uploader();
    ?>
    That will you can change the default upload directory, the max file size, and the file types aloud.
    Last edited by Bryon; 08-03-2005 at 01:52 PM.

  8. #8
    evilchinesefood is offline x10Hosting Member evilchinesefood is an unknown quantity at this point
    Join Date
    Jul 2005
    Posts
    31

    Re: User Uploader

    ok its still does not work. Tell me exactly what i do with it. Where can it upload files at public_html or public_ftp

  9. #9
    Bryon is offline Administrator Bryon has disabled reputation
    Join Date
    Apr 2005
    Location
    Northfield, NH
    Posts
    7,608

    Re: User Uploader

    Make a file named "uploader.php" in the directory /public_html/. Then, copy and paste everything in here into that file, and save it:


    PHP Code:

    <?
    function uploader($num_of_uploads=1$file_types_array=array("txt","gif","jpeg"), $max_file_size=1048576$upload_dir="downloads/"){
      if(!
    is_numeric($max_file_size)){
       
    $max_file_size 1048576;
      }
      if(!isset(
    $_POST["submitted"])){
       
    $form "<form action='".$PHP_SELF."' method='post' enctype='multipart/form-data'>Upload files:<br /><input type='hidden' name='submitted' value='TRUE' id='".time()."'><input type='hidden' name='MAX_FILE_SIZE' value='".$max_file_size."'>";
       for(
    $x=0;$x<$num_of_uploads;$x++){
         
    $form .= "<input type='file' name='file[]'><font color='red'>*</font><br />";
       }
       
    $form .= "<input type='submit' value='Upload'><br /><font color='red'>*</font>Maximum file length (minus extension) is 15 characters. Anything over that will be cut to only 15 characters. Valid file type(s): ";
       for(
    $x=0;$x<count($file_types_array);$x++){
         if(
    $x<count($file_types_array)-1){
           
    $form .= $file_types_array[$x].", ";
         }else{
           
    $form .= $file_types_array[$x].".";
         }
       }
       
    $form .= "</form>";
       echo(
    $form);
      }else{
       foreach(
    $_FILES["file"]["error"] as $key => $value){
         if(
    $_FILES["file"]["name"][$key]!=""){
           if(
    $value==UPLOAD_ERR_OK){
             
    $origfilename $_FILES["file"]["name"][$key];
             
    $filename explode("."$_FILES["file"]["name"][$key]);
             
    $filenameext $filename[count($filename)-1];
             unset(
    $filename[count($filename)-1]);
             
    $filename implode("."$filename);
             
    $filename substr($filename015).".".$filenameext;
             
    $file_ext_allow FALSE;
             for(
    $x=0;$x<count($file_types_array);$x++){
               if(
    $filenameext==$file_types_array[$x]){
                 
    $file_ext_allow TRUE;
               }
             }
             if(
    $file_ext_allow){
               if(
    $_FILES["file"]["size"][$key]<$max_file_size){
                 if(
    move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename)){
                   echo(
    "File uploaded successfully. - <a href='".$upload_dir.$filename."' target='_blank'>".$filename."</a><br />");
                 }else{
                   echo(
    $origfilename." was not successfully uploaded<br />");
                 }
               }else{
                 echo(
    $origfilename." was too big, not uploaded<br />");
               }
             }else{
               echo(
    $origfilename." had an invalid file extension, not uploaded<br />");
             }
           }else{
             echo(
    $origfilename." was not successfully uploaded<br />");
           }
         }
       }
      }
    }

    echo 
    uploader();
    ?>
    Then, create a directory/folder named "downloads" in /public_html/. Next, go to http://[your site]/uploader.php and try it out.

  10. #10
    evilchinesefood is offline x10Hosting Member evilchinesefood is an unknown quantity at this point
    Join Date
    Jul 2005
    Posts
    31

    Re: User Uploader

    ok it works thanks. Now can someone take my code and and how i want it to look. I cant get it to work in PHP. I only know html.

    PHP Code:
    <html dir="ltr">
        <head>
            <title>Darkware Uploader v1</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1;" />
            <meta name="description" content="Darkware Uploader" />
            <meta name="keywords" content="PHP, upload, free, open, source, SFU, simple, simplicity" />
            <style type="text/css">
            <!--
            body {
               font-family: Tahoma, verdana; font-size: 12px;
            }
            p.header {
               font-size: 18px;
            }
               a:link, a:visited {
               color: #009999; text-decoration:none;
            }
            a:active {
                color: #FF6600; text-decoration:none;
            }
            td {
                font-size:12px;
            }
            td.note {
                font-size:10px;
            }
             -->
            </style>
        </head>
      <body>
    <p style="margin: 0 20" align="center">&nbsp;</p>
    <p style="margin: 0 20" align="center">&nbsp;</p>
    <p style="margin: 0 20" align="center">&nbsp;</p>
    <p style="margin: 0 20" align="center">&nbsp;</p> 
    <p align="center" class="header">Darkware Uploader V1</p><table width="20%" border="0" align="center" style="border-collapse: collapse;">

    <center><?
    function uploader($num_of_uploads=1$file_types_array=array("exe","rar","zip","rtf","txt","gm6","doc","mp3"), $max_file_size=10000000$upload_dir="userdownloads/"){
      if(!
    is_numeric($max_file_size)){
       
    $max_file_size 10000000;
      }
      if(!isset(
    $_POST["submitted"])){
       
    $form "<form action='".$PHP_SELF."' method='post' enctype='multipart/form-data'><center><br /><input type='hidden' name='submitted' value='TRUE' id='".time()."'><input type='hidden' name='MAX_FILE_SIZE' value='".$max_file_size."'>";
       for(
    $x=0;$x<$num_of_uploads;$x++){
         
    $form .= "<input type='file' name='file[]'><br />";
       }
       
    $form .= "<br />
    <p><b>Max File Size:</b> 10M
    <p><b>Allowed Extensions</b>: "
    ;
       for(
    $x=0;$x<count($file_types_array);$x++){
         if(
    $x<count($file_types_array)-1){
           
    $form .= $file_types_array[$x].", ";
         }else{
           
    $form .= $file_types_array[$x].". </p><p><input type='submit' value='Upload'></p>";
         }
       }
       
    $form .= "</form>";
       echo(
    $form);
      }else{
       foreach(
    $_FILES["file"]["error"] as $key => $value){
         if(
    $_FILES["file"]["name"][$key]!=""){
           if(
    $value==UPLOAD_ERR_OK){
             
    $origfilename $_FILES["file"]["name"][$key];
             
    $filename explode("."$_FILES["file"]["name"][$key]);
             
    $filenameext $filename[count($filename)-1];
             unset(
    $filename[count($filename)-1]);
             
    $filename implode("."$filename);
             
    $filename substr($filename015).".".$filenameext;
             
    $file_ext_allow FALSE;
             for(
    $x=0;$x<count($file_types_array);$x++){
               if(
    $filenameext==$file_types_array[$x]){
                 
    $file_ext_allow TRUE;
               }
             }
             if(
    $file_ext_allow){
               if(
    $_FILES["file"]["size"][$key]<$max_file_size){
                 if(
    move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename)){
                   echo(
    "File uploaded successfully. - <a href='".$upload_dir.$filename."' target='_blank'>".$filename."</a><br />");
                 }else{
                   echo(
    $origfilename." was not successfully uploaded<br />");
                 }
               }else{
                 echo(
    $origfilename." was too big, not uploaded<br />");
               }
             }else{
               echo(
    $origfilename." had an invalid file extension, not uploaded<br />");
             }
           }else{
             echo(
    $origfilename." was not successfully uploaded<br /></center>");
           }
         }
       }
      }
    }


    echo 
    uploader();
    ?>


    How i want it to look:

    PHP Code:
     <html dir="ltr">
        <
    head>
            <
    title>Darkware</title>
            <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1;" />
            <
    meta name="description" content="Darkware" />
            <
    meta name="keywords" content="PHP, upload, free, open, source, SFU, simple, simplicity" />
            <
    style type="text/css">
            <!--
            
    body {
               
    font-familyTahomaverdanafont-size12px;
            }
            
    p.header {
               
    font-size18px;
            }
               
    a:linka:visited {
               
    color#009999; text-decoration:none;
            
    }
            
    a:active {
                
    color#FF6600; text-decoration:none;
            
    }
            
    td {
                
    font-size:12px;
            }
            
    td.note {
                
    font-size:10px;
            }
             -->
            </
    style>
        </
    head>
      <
    body>
     <
    p align="center" class="header">Darkware V1</p><table width="20%" border="0" align="center" style="border-collapse: collapse;">
       <
    tr>
          <
    td width="100%" align="center">
                <
    form method="post" enctype="multipart/form-data" action="/files/upload.php">
                <
    input type="hidden" name="MAX_FILE_SIZE" value="10649600" />
                <
    input type="file" name="SFUfile[]" size="20" /><br /></td>
       </
    tr>
       <
    tr>
          <
    td width="100%" align="left">
            <
    span style="font-size: 7pt; font-family: tahoma, verdana;"><b>Size Limit</b>: 10.16 MB<br />
       <
    b>Allowed Extensions</b>: gifjpgpngtxtdocwpdzipexemp3rar.<br /></span></td>
       </
    tr>
       <
    tr>
          <
    td align="center">
          <
    span style="font-size: 7pt; font-family: tahoma, verdana;">Powered By: <a href="http://www.darkware.uni.cc" target="_blank">&copyDarkware 2004 2005. All Rights Reserved.</a></span><br />
            <
    input type="submit" value="  Upload  " name="SFUsubmit" /></td>
       </
    tr>
        </
    form>
    </
    table>
               <
    p align="center"><span style="font-size: 8pt;"><b>Powered By:</bDarkware<br />
            </
    span></p>
        </
    body>
    </
    html

+ Reply to Thread
Page 1 of 2 12 LastLast

Similar Threads

  1. PHP: User Logging
    By pulse__xx in forum Tutorials
    Replies: 3
    Last Post: 11-13-2005, 11:59 AM
  2. PHP BB 2.0.16 Manual instalation
    By GFIV in forum Free Hosting
    Replies: 8
    Last Post: 09-14-2005, 12:40 PM
  3. Do we use the Ranking system here?
    By Cycloneflame in forum Off Topic
    Replies: 14
    Last Post: 04-28-2005, 10:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers