#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    8
    Rep Power
    0

    Issue with $_FILES


    Hi,

    I have a strange issue in a script for uploading images.
    I have a page to modify products.
    The logic function of the page is that if I do not select the modification of the image product, the script "skip" the code to upload and continues with the rest of the script.
    I put a check on $ _FILES after sending the form, but the result is
    $ _FILES ['FleImage'] ['name'] is always NOT empty.
    but print_r ($ _FILES) say to me that array is empty.

    PHP Code:
    echo"<pre>"
    print_r($_FILES); 
    echo
    "</pre>"

    $name $_FILES['fleImage']['name']; 
    if (empty(
    $name)) { echo "is empty"

    else 

    echo 
    "is not empty";} 
    then i created a simple test page with forms and controls equal to the original page:
    PHP Code:
    <!DOCTYPE html> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    </head> 
    <body> 

    <form action="" method="post" enctype="multipart/form-data" name="prova"> 
    <input name="fleImage" type="file" id="fleImage" class="box" multiple="multiple"> 
    <input name="modify" type="submit" value="Modify Product"> 
    </form> 

    <?php echo"<pre>"
    print_r($_FILES); 
    echo
    "</pre>"

    $name $_FILES['fleImage']['name']; 
    if (empty(
    $name)) 

    echo 
    "is empty"
    } else {
    echo 
    "is not empty";} ?> 

    </body> 
    </html>
    and this example works correctly!
    Why?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,508
    Rep Power
    594
    Use '!isset' rather than 'empty'.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    8
    Rep Power
    0
    hi gw1500se,

    I used !isset($name) but does not work..

    Selecting an image:

    Code:
    Array ( 
    [fleImage] => Array 
    ( [name] => Array ( [0] => IMG_0219.JPG ) 
    [type] => Array 
    ( [0] => image/jpeg ) 
    [tmp_name] => Array 
    ( [0] => E:\xampp\tmp\php2D01.tmp ) 
    [error] => Array ( [0] => 0 ) 
    [size] => Array ( [0] => 3311146 ) 
    ) 
    )
    result: is isset

    NOT Selecting an image:

    Code:
    Array ( 
    [fleImage] => Array 
    ( [name] => Array ( [0] => )
     [type] => Array ( [0] => ) 
    [tmp_name] => Array ( [0] => )
     [error] => Array ( [0] => 4 ) 
    [size] => Array ( [0] => 0 ) 
    ) 
    )
    result: is isset
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,508
    Rep Power
    594
    Are you using it on $_FILES?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    8
    Rep Power
    0
    yes

    PHP Code:
    $name $_FILES['fleImage']['name']; 
    if (!isset(
    $name)) {
    .... 
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,508
    Rep Power
    594
    Use it to check $_FILES before setting $name.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    8
    Rep Power
    0
    Does not work ..
    I try to summarize the entire operation:

    form
    Code:
    <form action="processProduct.php?action=modifyProduct&productId=<?php echo $productId; ?>" method="post" enctype="multipart/form-data" name="frmAddProduct" id="frmAddProduct">
    At the submit i send everything to the file processProduct.php

    PHP Code:
    $action = isset($_GET['action']) ? $_GET['action'] : '';
     switch (
    $action) {
    case 
    'modifyProduct' :
            
    test();
            break;
    }

    function 
    test()
    {


    echo
    "<pre>";
    print_r($_FILES);
    echo
    "</pre>";

    if (!isset(
    $_FILES['fleImage']['name'])) {

    echo 
    "is empty"
    } else {
    echo 
    "is not empty";
    }
     } 
    and that's it ... but it does not work

    I do not understand why the test page I posted beginning of this thread works perfectly and this test do not work...
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,508
    Rep Power
    594
    What part does not work?
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    8
    Rep Power
    0
    The control on $_FILES!

    i used empty() and !isset()
    i send data from the form with and without images (checked with print_r ) but result is always "is not empty"!

IMN logo majestic logo threadwatch logo seochat tools logo