Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default ANOTHER PHP question...

    Oh my, I look like an amateur... (I am rlly )

    anyway, I'm making a multi-upload image script, yet the loop work, the only thing is, it only copies the first image....

    Code:
    PHP Code:
     define ("MAX_SIZE","51200");  // 50mb

    //This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
     
    function getExtension2($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;

     if(isset(
    $_POST['upload_media2'])) 
     {
         for(
    $x=0;$x<51;$x++){
         
    $album $_POST['albums'];
         if(empty(
    $album)){
             
    $album "../_imgs/_albums/";
             
    $album2 "0";
         }else{
             
    $album "../_imgs/_albums/{$album}";
             
    $get_alb mysql_fetch_object(mysql_query("SELECT * FROM `albums` WHERE `name`='{$album}'"));
             
    $album2 $get_alb->id;
         }
         if(!
    is_dir($album)){
             
    str_replace("/"""$album);
             
    mkdir($album);
             
    chmod($album0777);
         }
         
    //reads the name of the file the user submitted for uploading
         
    $image=$_FILES['image' $x]['name'];
         
    //if it is not empty
         
    if ($image
         {
         
    //get the original name of the file from the clients machine
             
    $filename stripslashes($_FILES['image' $x]['name']);
         
    //get the extension of the file in a lower case format
              
    $extension getExtension2($filename);
             
    $extension strtolower($extension);
         
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
        //otherwise we will do more tests
     
    if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
             {
            
    //print error message
                 
    echo '<h1>Unknown extension!</h1>';
                 
    $errors=1;
             }
             else
             {
    //get the size of the image in bytes
     //$_FILES['image']['tmp_name'] is the temporary filename of the file
     //in which the uploaded file was stored on the server
     
    $size=filesize($_FILES['image' $x]['tmp_name']);

    //compare the size with the maxim size we defined and print error if bigger
    if ($size MAX_SIZE*1024)
    {
        echo 
    '<h1>You have exceeded the size limit!</h1>';
        
    $errors=1;
    }

    //we will give an unique name, for example the time in unix time format
    $image_name=time().'.'.$extension;
    //the new name will be containing the full path where will be stored (images folder)
    $newname=$album "/" $image_name;
    //we verify if the image has been uploaded, and print error instead
    $copied copy($_FILES['image' $x]['tmp_name'], $newname);
    chmod($newname0777);
    mysql_query("INSERT INTO `imgs` (`img_link`, `alb`) VALUES ('{$newname}', '{$album2}')");
    if (!
    $copied
    {
        echo 
    '<h1>Copy unsuccessfull!</h1>';
        
    $errors=1;
    }}}}}

    //If no errors registred, print the success message
     
    if(isset($_POST['upload_media2']) && !$errors
     {
         if(isset(
    $_SERVER['HTTP_REFERER'])){
            echo 
    "<meta http-equiv=\"refresh\" content=\"0;url={$_SERVER['HTTP_REFERER']}\">";
        }elseif(
    $album != ""){
            
    $alit mysql_fetch_object(mysql_query("SELECT * FROM `albums` WHERE `name`='{$album}'"));
            echo 
    "<meta http-equiv=\"refresh\" content=\"0;url=?media&viewalb&id={$alit->id}\">";
        }elseif(empty(
    $album)){
            echo 
    "<meta http-equiv=\"refresh\" content=\"0;url=?media&manage\">";
        }
     }
            
    ?> 
    I know its messily coded, Im still working on it.

    +REP

    Lew.
    Im not here to be loved, I love to be hated :-}


  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    What's the deal in repeating it 51 times?

  3. #3
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    PHP Code:
    }}}}} 
    lol, tidy the code up and I will help, your code is stupidly messy
    we're smiling but we're close to tears, even after all these years

  4. #4
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by MattFr View Post
    PHP Code:
    }}}}} 
    lol, tidy the code up and I will help, your code is stupidly messy
    Hence why I said "I know its messily coded, Im still working on it."

    And I am repeating it 51 times as it is a multi-upload script with 51 upload boxes... :/

    Help?

    Lew.
    Im not here to be loved, I love to be hated :-}


  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    What is your HTML code for the form..

  6. #6
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    What's the possibility of somebody uploading 51 images? Doing it 51 times without any need will just drain your server resources. Would be best to maybe add a bit of javascript that adds a file upload field when needed and then submit the total amount of elements in use.

  7. #7
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Moh View Post
    What's the possibility of somebody uploading 51 images? Doing it 51 times without any need will just drain your server resources. Would be best to maybe add a bit of javascript that adds a file upload field when needed and then submit the total amount of elements in use.
    Yes possibly, but I need this to work for the moment...

    Lew.
    Im not here to be loved, I love to be hated :-}


  8. #8
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Post your HTML for your upload form..

  9. #9
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <form name="newad2" method="post" enctype="multipart/form-data" action="">
    <input name="albums" type="hidden" value="<?php echo $alb_info1->name?>" />

    <select name="albums">
                            <option value="">No album</option>
                            <?php $album mysql_query("SELECT * FROM `albums`");
                            while(
    $val4 mysql_fetch_object($album)){
                                echo 
    "<option value=\"{$val4->name}\">{$val4->name}</option>";
                            }
                            
    ?>
                          </select>
                          <?php ?>
                          <hr />
                          <?php for($t=0;$t<51;$t++){
                              echo 
    "<input type=\"file\" name=\"image{$t}\" id=\"image{$t}\">";
                          }
                          
    ?>
    <input name="upload_media2" type="submit" value="Upload image">
    </form>
    Im not here to be loved, I love to be hated :-}


  10. #10
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    That's not the way you do it there bud... never has worked for me... you need to name the file something with brackets... userfile[].

    It is then put into an array.. $_FILES['userfile]['name'][0]. I suggest you read this tutorial: http://www.phpeasystep.com/phptu/2.html

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
  •