Link to home
Start Free TrialLog in
Avatar of n00b0101
n00b0101

asked on

file upload script uploads empty file

I'm using the attached code to upload an image file.  The sql data is inserted correctly, and the filename is in the destination directory as expected, but the filesize is 0.  Help?


if(is_uploaded_file($_FILES['form_image']['tmp_name']))  {
        // file uploaded to server
        $imageInfo = getimagesize($_FILES['form_image']['tmp_name']);
        $width = $imageInfo[0];
        $height = $imageInfo[1];
        $image_type = $imageInfo[2];
 
        move_uploaded_file($_FILES['form_image']['tmp_name'], "./pics/images/sample_dir/album_/".$_FILES['form_image']['name']);
 
        if(isset($_POST['field1'])) {
          $myfield1 = trim(htmlentities($_POST['field1']));
        } else {
          $myfield1 = '';
        }
 
        if(isset($_POST['myfield2'])) {
          $myfield2 = trim(htmlentities($_POST['myfield2']));
        } else {
          $myfield2 = '';
        }
 
      $fnp = 'sample_dir/album_/'.$_FILES['form_image']['name'];
      $query = "INSERT INTO pics (path, caption, description, date_submitted)
                VALUES ('".$fnp."', '".$caption."', '".$description."', NOW())";
      $result = $database->query($query);
      if($result) {
			echo 'Success!';
      }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of dr_dedo
dr_dedo
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of n00b0101
n00b0101

ASKER

Well, I guess it's got something to do with file size, but how do I control that?  
Avatar of Loganathan Natarajan
try this to control the file size..,

$file_size=$_FILES['file']['size'];

if($file_size >= $limit_size){
          echo "Your file size is over limit<BR>";
           echo "Your file size = ".$file_size;
           echo "<BR>File size limit = 50000 k";
}
else {
          <<<Upload process>>>

}
logudotcom:
if file is over size limit, it would fail to be uploaded in the first place, so you can't check its size

n00b0101:
did u try to upload small files, a 50k or something ? does it work ? it it works and it is a file size problem for sure, then you should contact you site admin to increase max alloed uploaded file size. if you are the one incharge for the server, you can change that from php.ini
Even though this didn't provide the outright solution, it still pointed me in the right direction, so thanks!