Jump to content

image upload problem


vmicchia

Recommended Posts

I am working on a file upload that stores the image in the database. my upload field is this:

<input type="file" name="image1[]" />

 

and my php to process the file and upload it is this:

$maxsize = 100000;

if(is_uploaded_file($_FILES['image1']['tmp_name'])) {

        //check the file is less than the maximum file size
        if($_FILES['image1']['size'] < $maxsize)
            {
         //prepare the image for insertion
        $imgData =addslashes(file_get_contents($_FILES['image1']['tmp_name']));
        $imgData = addslashes($_FILES['image1']);

         //get the image info..
          $size = getimagesize($_FILES['image1']['tmp_name']);

          $id = $name.'_'.$SKU;

         //our sql query
        $sql = "INSERT INTO Images
                ( imageID , Type ,Image, Size, FileName, DateAdded, Category, SKU. Description)
                VALUES
                ('".$id."', '".$size['mime']."', '".$imgData."', '".$size[3]."', '".$_FILES['image1']['name']."', NOW(), Fabric, '".$SKU."', '".$desc."'";

         echo $sql;
        // insert the image
        if(!mysql_query($sql)) {
            echo 'Unable to upload file';
            
        }
     }
    }
    else {
         // if the file is not less than the maximum allowed, print an error
         echo
          '<div>File exceeds the Maximum File limit</div>
          <div>Maximum File limit is '.$maxsize.'</div>
          <div>File '.$_FILES['image1']['name'].' is '.$_FILES['image1']['size'].' bytes</div>
          <hr />';
         } 

 

at first the sql just wouldn't work. Now I get this error every time for some reason

 

File exceeds the Maximum File limit

Maximum File limit is 100000

File Array is Array bytes

 

which seems odd because it does not even return the file size or name correctly.

 

 

Link to comment
https://forums.phpfreaks.com/topic/227919-image-upload-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.