SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Multiple Array of images Upload

    Hey,

    I am trying to upload multiple images to my server, and also insert the path into my databas table, but it dont seem to be working. My code is shown below, is there something that i have missed out?

    I've been at it all day and cant seem to figure it out..

    PHP Code:
                    include("conn.php");
                                                
                    
    $path1"garments/".$HTTP_POST_FILES['ufile']['name'][0];
                    
    $path2"garments/".$HTTP_POST_FILES['ufile']['name'][1];
                    
    $path3"garments/".$HTTP_POST_FILES['ufile']['name'][2];
                    
    $path4"garments/".$HTTP_POST_FILES['ufile']['name'][3];
                    
    $path5"garments/".$HTTP_POST_FILES['ufile']['name'][4];
                    
                    
    copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
                    
    copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
                    
    copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
                    
    copy($HTTP_POST_FILES['ufile']['tmp_name'][3], $path4);
                    
    copy($HTTP_POST_FILES['ufile']['tmp_name'][4], $path5);
                                                    
                    
    $filesize1=$HTTP_POST_FILES['ufile']['size'][0];
                    
    $filesize2=$HTTP_POST_FILES['ufile']['size'][1];
                    
    $filesize3=$HTTP_POST_FILES['ufile']['size'][2];
                    
    $filesize4=$HTTP_POST_FILES['ufile']['size'][3];
                    
    $filesize5=$HTTP_POST_FILES['ufile']['size'][4];
                    
                    
    $insert "INSERT INTO category_selection (cat_id, selection_name, item_name, item_description, item_price, main_image, image_1, image_2, image_3, image_4, date_uploaded) VALUES 
                    (
                    '"
    .$_POST['thing']."', 
                    '"
    .$_POST['txt_c_name']."', 
                    '"
    .$_POST['txt_name']."', 
                    '"
    .$_POST['txt_desc']."', 
                    '"
    .$_POST['txt_price']."', 
                    
    $path1,
                    
    $path2,
                    
    $path3,
                    
    $path4,
                    
    $path5,
                    now()
                    )"
    ;
                    
    $add_member mysql_query($insert);

                    if(
    $filesize1 && $filesize2 && $filesize3 && $filesize4 && $filesize5 != 0)
                    {
                    echo 
    "We have recieved your files";
                    }
                    
                    else {
                    echo 
    "ERROR.....";
                    }
                                    
                    if(
    $filesize1==0) {
                    echo 
    "There're something error in your first file";
                    echo 
    "<BR />";
                    }
                    
                    if(
    $filesize2==0) {
                    echo 
    "There're something error in your second file";
                    echo 
    "<BR />";
                    }
                    
                    if(
    $filesize3==0) {
                    echo 
    "There're something error in your third file";
                    echo 
    "<BR />";
                    }
                    
                    if(
    $filesize4==0) {
                    echo 
    "There're something error in your fourth file";
                    echo 
    "<BR />";
                    }
                    
                    if(
    $filesize5==0) {
                    echo 
    "There're something error in your fifth file";
                    echo 
    "<BR />";
                    } 
    Regards

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    $_FILES['ufile'][0]['name'] not $_FILES['ufile']['name'][0] ?
    Last edited by Dan Grossman; Aug 17, 2009 at 15:54.

  3. #3
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    Thanks for the reply, but that still does not work..

    This is the error message i am receving:-

    PHP Code:

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 148

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 149

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 150

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 151

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 152 
    This refers to the following lines:-

    PHP Code:
                    copy($HTTP_POST_FILES['ufile'][0]['tmp_name'], $path1);
                    
    copy($HTTP_POST_FILES['ufile'][1]['tmp_name'], $path2);
                    
    copy($HTTP_POST_FILES['ufile'][2]['tmp_name'], $path3);
                    
    copy($HTTP_POST_FILES['ufile'][3]['tmp_name'], $path4);
                    
    copy($HTTP_POST_FILES['ufile'][4]['tmp_name'], $path5); 

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you just var_dump $_FILES so you can see what the array looks like instead of guessing?

    $HTTP_POST_FILES is deprecated

  5. #5
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I have tried var_dump and it gives a rather long line shown below:-

    PHP Code:
    array(1) { ["ufile"]=>  array(5) { ["name"]=>  array(5) { [0]=>  string(13"corrupt24.jpg" [1]=>  string(13"corrupt24.jpg" [2]=>  string(13"corrupt24.jpg" [3]=>  string(13"corrupt24.jpg" [4]=>  string(13"corrupt24.jpg" } ["type"]=>  array(5) { [0]=>  string(10"image/jpeg" [1]=>  string(10"image/jpeg" [2]=>  string(10"image/jpeg" [3]=>  string(10"image/jpeg" [4]=>  string(10"image/jpeg" } ["tmp_name"]=>  array(5) { [0]=>  string(14"/tmp/phpm5U7ws" [1]=>  string(14"/tmp/phpoI4qWA" [2]=>  string(14"/tmp/phpiRqeFM" [3]=>  string(14"/tmp/phpxC1DZ1" [4]=>  string(14"/tmp/phpeeiOTk" } ["error"]=>  array(5) { [0]=>  int(0) [1]=>  int(0) [2]=>  int(0) [3]=>  int(0) [4]=>  int(0) } ["size"]=>  array(5) { [0]=>  int(33208) [1]=>  int(33208) [2]=>  int(33208) [3]=>  int(33208) [4]=>  int(33208) } } } 
    I have also changed the $HTTP_POST_FILES to _FILES..

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So the copy() calls were working originally?

    Is it just the SQL query that's not running?

    You don't have single quotes around your path names in the query which it needs

  7. #7
    SitePoint Zealot CalebMingle's Avatar
    Join Date
    Jul 2007
    Posts
    135
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    <?php
    echo "<pre>";

    print_r($_FILES);

    ?>
    And you'll see how the array is setup better then var_dump
    :: Caleb Mingle (@dentafrice)
    :: PHP Developer.
    :: g+: http://gplus.to/mingle

  8. #8
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I have tried the better display of arrays and i get the following:-

    PHP Code:
    Warningcopy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 148

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 149

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 150

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 151

    Warning
    copy() [function.copy]: Filename cannot be empty in /domains/skindeepapparel.com/http/lou/admin.php on line 152

    Array
    (
        [
    ufile] => Array
            (
                [
    name] => Array
                    (
                        [
    0] => corrupt24.jpg
                        
    [1] => corrupt24.jpg
                        
    [2] => corrupt24.jpg
                        
    [3] => corrupt24.jpg
                        
    [4] => corrupt24.jpg
                    
    )

                [
    type] => Array
                    (
                        [
    0] => image/jpeg
                        
    [1] => image/jpeg
                        
    [2] => image/jpeg
                        
    [3] => image/jpeg
                        
    [4] => image/jpeg
                    
    )

                [
    tmp_name] => Array
                    (
                        [
    0] => /tmp/php6ZqUnA
                        
    [1] => /tmp/phppv05pv
                        
    [2] => /tmp/phpR24Yis
                        
    [3] => /tmp/phpCblmZq
                        
    [4] => /tmp/phpDQKAyr
                    
    )

                [
    error] => Array
                    (
                        [
    0] => 0
                        
    [1] => 0
                        
    [2] => 0
                        
    [3] => 0
                        
    [4] => 0
                    
    )

                [
    size] => Array
                    (
                        [
    0] => 33208
                        
    [1] => 33208
                        
    [2] => 33208
                        
    [3] => 33208
                        
    [4] => 33208
                    
    )

            )


    What does this mean?

    Regard

  9. #9
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    I have managed to get the code working using the PHP Manual. It uses the following code:-

    PHP Code:
                    include("conn.php");
                                                                                
                    
    $insert "INSERT INTO category_selection (cat_id, selection_name, item_name, item_description, item_price, main_image, image_1, image_2, image_3, image_4, date_uploaded) VALUES 
                    (
                    '"
    .$_POST['thing']."', 
                    '"
    .$_POST['txt_c_name']."', 
                    '"
    .$_POST['txt_name']."', 
                    '"
    .$_POST['txt_desc']."', 
                    '"
    .$_POST['txt_price']."', 
                    '"
    .$_FILES['ufile']."',
                    '"
    .$_FILES['ufile']."',
                    '"
    .$_FILES['ufile']."',
                    '"
    .$_FILES['ufile']."',
                    '"
    .$_FILES['ufile']."',
                    now()
                    )"
    ;
                    
    $add_member mysql_query($insert);
                    
                    
    //places files into same dir as form resides
                    
    foreach ($_FILES["ufile"]["error"] as $key => $error
                    {
                       if (
    $error == UPLOAD_ERR_OK
                       {
                           echo
    "$error_codes[$error]";
                           
    move_uploaded_file(
                             
    $_FILES["ufile"]["tmp_name"][$key], 
                             
    'garments/'.$_FILES["ufile"]["name"][$key]
                           ) or die(
    "Problems with upload");
                       }
                    } 
    but the insert statement is not working, i think this is because i have 5 upload files, so i need to differentiate between them all. My form looks as so:-

    PHP Code:
            <form action="" name="update_mens" method="post" enctype="multipart/form-data">
            <
    table cellspacing="6">
            <
    tr><td>Main Image URL</td><td><input name="ufile[]" type="file" id="ufile[]"/></td></tr>
            <
    tr><td>Thumbnail 1</td><td><input name="ufile[]" type="file" id="ufile[]"/></td></tr>
            <
    tr><td>Thumbnail 2</td><td><input name="ufile[]" type="file" id="ufile[]"/></td></tr>
            <
    tr><td>Thumbnail 3</td><td><input name="ufile[]" type="file" id="ufile[]"/></td></tr>        
            <
    tr><td>Thumbnail 4</td><td><input name="ufile[]" type="file" id="ufile[]"/></td></tr>
            <
    tr><td><input type="submit" name="btn_update" value="Upload"/></td></tr>
            </
    table>
            </
    form
    how can i get this insert statement to add the file paths of each file upload?

    regards


Bookmarks

Posting Permissions

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