SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error in File Upload

    Hi,

    Can anyone help for this. In my project i uploaded files by using this query

    @list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']);
    // Get image type.
    // We use @ to omit errors
    if ($imtype == 3) // cheking image type
    $photo_ext="png"; // to use it later in HTTP headers
    elseif ($imtype == 2)
    $photo_ext="jpeg";
    elseif ($imtype == 1)
    $photo_ext="gif";

    $photo = file_get_contents($_FILES['photo']['tmp_name']);
    $photo = mysql_real_escape_string($photo);

    if($photo!=''){ $db->execute("UPDATE `emp_personal` SET `photo`='$photo', `photo_ext`='$photo_ext' WHERE `emp_id` ='$emp_id'");}

    Upto some days it worked but, now it didn't give error and files are not uploaded. In this code files are not transfer to any folder only insert into database and accessed by some php code.


    why this problem comes, any limit in saving or what reason can anyone suggest??

    Thanks in advance

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Location
    Surrey, UK
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code you posted will insert the actual image into a database but won't save the image file anywhere. Is there more that you haven't shown? If they're being inserted into the database OK then the upload is working, at least partially.
    Martin.

  3. #3
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For viewing the images which is uploaded by this code:

    <img style="margin:0 10px;" src='photoview.php?show=<?php echo $emp_id; ?>' height="120" alt=' ' />

    if (isset($_GET['show']))
    {
    $emp_id = intval($_GET['show']);

    $result = mysql_query("SELECT photo_ext, photo
    FROM `emp_personal`
    WHERE emp_id=$emp_id LIMIT 1");

    list($photo_ext, $photo) = mysql_fetch_row($result);


    $photo_check=$photo;
    if($photo_check!=''){

    // outputing HTTP headers
    header('Content-Length: '.strlen($photo));
    header("Content-type: image/{$photo_ext}");
    //echo $photo;
    echo $photo;
    }else {

    $u="User.png";
    //header('Content-Length: '.strlen($photo));
    header("Content-type: image/png");

    echo file_get_contents("images/$u");


    }
    //exit();
    }


    but i don't know for which reason i didn't see the photos.
    can u say that on which reasons a file can't upload?? i didn't get the reason, when i upload a image it didn't see on action page...

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Location
    Surrey, UK
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I think I see what you mean. The first thing I would do is output $_FILES on your upload page to see what's there:

    PHP Code:
    print_r($_FILES); 
    It sounds like the upload is failing for some reason but by default it won't notify you. $_FILES will show you if there are any errors, and if not it might give a clue as to what is happening.

    From there I would output the content of $imtype and $photo to see how far it is getting before something fails.
    Martin.

  5. #5
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank u for the reply.

  6. #6
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi

    ya right when i print the $FILES it shows me the

    Array ( [photo] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [signature] => Array ( [name] => 1.jpg [type] => [tmp_name] => [error] => 6 [size] => 0 ) )

    $signature = mysql_real_escape_string($signature);
    this line comes before print_r($_FILES); but, when i echo the signature variable it shows blank... how it can possible...

    i didn't understand that, why the problems come... can u help me for this.

  7. #7
    SitePoint Member
    Join Date
    Nov 2011
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks it solved..

    I just removed the tmp folder. When i create the folder it works......

  8. #8
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Always, without fail, the first thing to check is the error number.

    In your case:
    Code:
     [error] => 6
    Should be error => 0, read the error codes page.

    pseudocode handling should be something like:

    Code:
    if( $array['error'] > 0 ){
    
    // something went wrong, tell the user or log the error
    
    } else {
    
    // carry on with the operation
    
    }
    Glad you got it solved though ...


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
  •