HabboxWiki needs you!
Are you a Habbo buff? Or maybe a rare trader with a bunch of LTDs? Get involved with HabboxWiki to share your knowledge!
Join our team!
Whether you're raving for rares, excited for events or happy helping, there's something for you! Click here to apply
Need a helping hand?
Check out our guides for all things to help you make friends, make rooms, and make money!


Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Apr 2006
    Location
    Australia
    Posts
    307
    Tokens
    0

    Default <input type="file"> help!

    I am making a form at the moment, and I have a <input type="file"> area there and I'm wondering how to get the items that people put it there to upload to a certain folder on my server.

    Help is much appreciated!

    Chris

  2. #2
    Join Date
    Apr 2008
    Location
    England.
    Posts
    1,324
    Tokens
    0

    Latest Awards:

    Default

    Use an uploader?

  3. #3
    Join Date
    Apr 2006
    Location
    Australia
    Posts
    307
    Tokens
    0

    Default

    What I am doing is it's for DJ Applications, and I want their DJ example clip which they are uploading to appear in a folder.

  4. #4
    Join Date
    Apr 2008
    Location
    England.
    Posts
    1,324
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?php
    echo "<center>"//We center the page.
    $sitename "sitename.com"//Put your site url here.
        
    switch ($_GET[page]) //We use the switch function to get the page.
        
    {
            default: 
    //Self explanatory
                
    echo "<form action='?page=upload' enctype='multipart/form-data' method='POST'>
                Upload:
                <input type='file' size='7' name='image' id='image'><br>
                <input type='submit' name='submit' value='Upload'></form>"
    ;
                break; 
    //Break upload
            
    case 'upload'//The upload case
                
    $filename $_FILES["img"]["name"];
                
    $tmp_name $_FILES["img"]["tmp_name"];
                
    $img "images/$filename"//You can edit the images piece to where your images will be displayed
                
    if (move_uploaded_file($tmp_name"images/".$filename)) { //And here - we also move the file
                    
    echo "Image upload complete!<br><img src='$img'><br>
                                    Forum ******?<br>
                                    <input type='text' name='image' size='30' value='[IMG]www."
    .$sitename.".com/files/upload/".$img."[/IMG]'>"// We display that their file has been uploaded, show then the url and show them a picture of their upload
                
    } else { //Lol the upload failed
                    
    die ("Don't bother uploading ever again.. seriously."); //True comment
                
    }
                            
                break; 
    //Break page
        
    }
    ?>
    Use that, change it round if you wish.

  5. #5
    Join Date
    Jul 2008
    Location
    Ellesmere Port
    Posts
    440
    Tokens
    0

    Default

    Try this
    Make a folder called djtrials in the same directory as this and it will work a treat
    At the bottom, it also shows the users OWN uploaded files only, provided you do trialup.php?djname=DJNAMEHERE
    name this file: trialup.php
    to make each users trial seperate, do trialup.php?djname=DJNAMEHERE
    and it will create a folder for each different DJNAMEHERE
    its also a good way to store all their stuff
    To allow more file types, just add more files to the array $FILE_EXTS

    I basically copied my user upload system but edited it for you
    Goodluck.
    PS: the maxfile size is set at 10mb - ample amount
    PHP Code:
    <?php
    $MAX_SIZE 
    10000000;
    $person $_GET['djname'];
    $FILE_EXTS  = array('.mp3','.wma','.asx'); 
    $DELETABLE  false;                               
    $site_name $_SERVER['HTTP_HOST'];
    $url_dir "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    $upload_dir "djtrials/".$person."/";
    $upload_url $url_dir."/djtrials/".$person;
    if (!
    is_dir("djtrials/".$person."")) {
      if (!
    mkdir($upload_dir))
          die (
    "Error 1 happend!");
      if (!
    chmod($upload_dir,0755))
          die (
    "Error 2 happend!");
      if (!
    chmod($upload_dir,0777)) 
        die (
    "Error 3 happend!");
    }
    if (
    $_FILES['userfile']) {
      
    $file_type $_FILES['userfile']['type']; 
      
    $file_name $_FILES['userfile']['name'];
      
    $file_ext strtolower(substr($file_name,strrpos($file_name,".")));
      if ( 
    $_FILES['userfile']['size'] > $MAX_SIZE
        echo 
    "The file size is over ".$MAX_SIZE." Bytes.";
      
    //File Extension Check
      
    else if (!in_array($file_ext$FILE_EXTS))
         echo 
    "<center>Sorry, the file ".$filename($file_type)." Is not allowed to be uploaded!</center>";
      else
          
    do_upload($upload_dir$upload_url);

    }
    else if (!
    $_FILES['userfile']);
    else 
        echo 
    "<center>Invalid file specified.</center>";
    /************************************************************
     *     List Files
     ************************************************************/
    $handle=opendir($upload_dir);
    $filelist "";
    while (
    $file readdir($handle)) {
       if(!
    is_dir($file) && !is_link($file)) {
          
    $filelist .= "<a href='$upload_dir/$file' rel=\"lightbox\" title=\"".$file."-Uploaded by ".$_SESSION['myusername']."\" rel=\"lightbox[".$_SESSION['myusername']."'s Uploads]\"\">".$file."</a>";
          if (
    $DELETABLE)
            
          
    $filelist .= " Added at  ".date("d-m H:i"filemtime($upload_dir.$file))
                       .
    "";
    $filelist .= "";
          
    $filelist .="<br>";
       }
    }

    function 
    do_upload($upload_dir$upload_url) {

        
    $temp_name $_FILES['userfile']['tmp_name'];
    function 
    getnumbertrial() {
        
    $file_name $person.time();.$_FILES['userfile']['name']; 
      
    $file_name str_replace("\\","",$file_name);
      
    $file_name str_replace("'","",$file_name);
        
    $file_path $upload_dir.$file_name;
        
    //File Name Check
      
    if ( $file_name =="") { 
          echo 
    "Invalid File Name Specified";
      }

      
    $result  =  move_uploaded_file($temp_name$file_path);
      if (!
    chmod($file_path,0777))
           
    $message "change permission to 777 failed.";
      else
        echo (
    $result)?"<center>$file_name WAS uploaded successfully, ".$name."!</center>" :
                   
    "     <center>There was an unknown error whilst uploading the file.</center>";
    }

    ?>
       <center><form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
         Upload File <input type="file" id="userfile" name="userfile">
         <input type="submit" name="upload" value="Upload">
       </form>
    </center>
     <br><b><u>YOUR Uploaded files:</u></b><br><br>
       <?=$filelist?>
    Last edited by NN-Dom; 02-08-2008 at 01:04 PM.

  6. #6
    Join Date
    Apr 2006
    Location
    Australia
    Posts
    307
    Tokens
    0

    Default

    Erm..

    I get this error with the above method.

    Code:
    Parse error: syntax error, unexpected '.' in /home/chrism/public_html/habbohut/apps/trialup.php on line 56

  7. #7
    Join Date
    Apr 2008
    Location
    England.
    Posts
    1,324
    Tokens
    0

    Latest Awards:

    Default

    Replace the . on line 56 with a ,

  8. #8
    Join Date
    Apr 2006
    Location
    Australia
    Posts
    307
    Tokens
    0

    Default

    Quote Originally Posted by Excellent View Post
    Replace the . on line 56 with a ,
    Then it has an unexpected ',' now.

  9. #9
    Join Date
    Jul 2008
    Location
    Ellesmere Port
    Posts
    440
    Tokens
    0

    Default

    hah my mistake, sorry - here you go

    PHP Code:
     <?php
    $MAX_SIZE 
    10000000;
    $person $_GET['djname'];
    $FILE_EXTS  = array('.mp3','.wma','.asx'); 
    $DELETABLE  false;                               
    $site_name $_SERVER['HTTP_HOST'];
    $url_dir "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    $upload_dir "djtrials/".$person."/";
    $upload_url $url_dir."/djtrials/".$person;
    if (!
    is_dir("djtrials/".$person."")) {
      if (!
    mkdir($upload_dir))
          die (
    "Error 1 happend!");
      if (!
    chmod($upload_dir,0755))
          die (
    "Error 2 happend!");
      if (!
    chmod($upload_dir,0777)) 
        die (
    "Error 3 happend!");
    }
    if (
    $_FILES['userfile']) {
      
    $file_type $_FILES['userfile']['type']; 
      
    $file_name $_FILES['userfile']['name'];
      
    $file_ext strtolower(substr($file_name,strrpos($file_name,".")));
      if ( 
    $_FILES['userfile']['size'] > $MAX_SIZE
        echo 
    "The file size is over ".$MAX_SIZE." Bytes.";
      
    //File Extension Check
      
    else if (!in_array($file_ext$FILE_EXTS))
         echo 
    "<center>Sorry, the file ".$filename($file_type)." Is not allowed to be uploaded!</center>";
      else
          
    do_upload($upload_dir$upload_url);

    }
    else if (!
    $_FILES['userfile']);
    else 
        echo 
    "<center>Invalid file specified.</center>";
    /************************************************************
     *     List Files
     ************************************************************/
    $handle=opendir($upload_dir);
    $filelist "";
    while (
    $file readdir($handle)) {
       if(!
    is_dir($file) && !is_link($file)) {
          
    $filelist .= "<a href='$upload_dir/$file' rel=\"lightbox\" title=\"".$file."-Uploaded by ".$_SESSION['myusername']."\" rel=\"lightbox[".$_SESSION['myusername']."'s Uploads]\"\">".$file."</a>";
          if (
    $DELETABLE)
            
          
    $filelist .= " Added at  ".date("d-m H:i"filemtime($upload_dir.$file))
                       .
    "";
    $filelist .= "";
          
    $filelist .="<br>";
       }
    }

    function 
    do_upload($upload_dir$upload_url) {

        
    $temp_name $_FILES['userfile']['tmp_name'];
    function 
    getnumbertrial() {
        
    $file_name $person.time();.$_FILES['userfile']['name']; 
      
    $file_name str_replace("\\","",$file_name);
      
    $file_name str_replace("'","",$file_name);
        
    $file_path $upload_dir.$file_name;
        
    //File Name Check
      
    if ( $file_name =="") { 
          echo 
    "Invalid File Name Specified";
      }

      
    $result  =  move_uploaded_file($temp_name$file_path);
      if (!
    chmod($file_path,0777))
           
    $message "change permission to 777 failed.";
      else
        echo (
    $result)?"<center>$file_name WAS uploaded successfully, ".$name."!</center>" :
                   
    "     <center>There was an unknown error whilst uploading the file.</center>";
    }

    ?>
       <center><form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
         Upload File <input type="file" id="userfile" name="userfile">
         <input type="submit" name="upload" value="Upload">
       </form>
    </center>
     <br><b><u>YOUR Uploaded files:</u></b><br><br>
       <?=$filelist?>

  10. #10
    Join Date
    Feb 2007
    Location
    Essex, England
    Posts
    1,392
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by TCG-Dom View Post
    hah my mistake, sorry - here you go

    PHP Code:
     <?php
    $MAX_SIZE 
    10000000;
    $person $_GET['djname'];
    $FILE_EXTS  = array('.mp3','.wma','.asx'); 
    $DELETABLE  false;                               
    $site_name $_SERVER['HTTP_HOST'];
    $url_dir "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
    $upload_dir "djtrials/".$person."/";
    $upload_url $url_dir."/djtrials/".$person;
    if (!
    is_dir("djtrials/".$person."")) {
      if (!
    mkdir($upload_dir))
          die (
    "Error 1 happend!");
      if (!
    chmod($upload_dir,0755))
          die (
    "Error 2 happend!");
      if (!
    chmod($upload_dir,0777)) 
        die (
    "Error 3 happend!");
    }
    if (
    $_FILES['userfile']) {
      
    $file_type $_FILES['userfile']['type']; 
      
    $file_name $_FILES['userfile']['name'];
      
    $file_ext strtolower(substr($file_name,strrpos($file_name,".")));
      if ( 
    $_FILES['userfile']['size'] > $MAX_SIZE
        echo 
    "The file size is over ".$MAX_SIZE." Bytes.";
      
    //File Extension Check
      
    else if (!in_array($file_ext$FILE_EXTS))
         echo 
    "<center>Sorry, the file ".$filename($file_type)." Is not allowed to be uploaded!</center>";
      else
          
    do_upload($upload_dir$upload_url);

    }
    else if (!
    $_FILES['userfile']);
    else 
        echo 
    "<center>Invalid file specified.</center>";
    /************************************************************
     *     List Files
     ************************************************************/
    $handle=opendir($upload_dir);
    $filelist "";
    while (
    $file readdir($handle)) {
       if(!
    is_dir($file) && !is_link($file)) {
          
    $filelist .= "<a href='$upload_dir/$file' rel=\"lightbox\" title=\"".$file."-Uploaded by ".$_SESSION['myusername']."\" rel=\"lightbox[".$_SESSION['myusername']."'s Uploads]\"\">".$file."</a>";
          if (
    $DELETABLE)
            
          
    $filelist .= " Added at  ".date("d-m H:i"filemtime($upload_dir.$file))
                       .
    "";
    $filelist .= "";
          
    $filelist .="<br>";
       }
    }

    function 
    do_upload($upload_dir$upload_url) {

        
    $temp_name $_FILES['userfile']['tmp_name'];
    function 
    getnumbertrial() {
        
    $file_name $person.time();.$_FILES['userfile']['name']; 
      
    $file_name str_replace("\\","",$file_name);
      
    $file_name str_replace("'","",$file_name);
        
    $file_path $upload_dir.$file_name;
        
    //File Name Check
      
    if ( $file_name =="") { 
          echo 
    "Invalid File Name Specified";
      }

      
    $result  =  move_uploaded_file($temp_name$file_path);
      if (!
    chmod($file_path,0777))
           
    $message "change permission to 777 failed.";
      else
        echo (
    $result)?"<center>$file_name WAS uploaded successfully, ".$name."!</center>" :
                   
    "     <center>There was an unknown error whilst uploading the file.</center>";
    }

    ?>
       <center><form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
         Upload File <input type="file" id="userfile" name="userfile">
         <input type="submit" name="upload" value="Upload">
       </form>
    </center>
     <br><b><u>YOUR Uploaded files:</u></b><br><br>
       <?=$filelist?>
    That was nice of you +rep.


Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •