0

in my php page I have <input type='file' name='aimage[]' id='aimage' /> and a snippet code to get this file as :

    foreach($_FILES["aimage"]["tmp_name"] as $file)
    {
    /***  get the image info. ***/
     if(is_uploaded_file($file) && getimagesize($file) != false){

    $size = getimagesize($file);
    /*** assign our variables ***/
    $type = $size['mime'];
    $imgfp = fopen($file, 'rb');
    $size = $size[3];
   // $name = $file['name'];
    $maxsize = 99999999;


    /***  check the file is less than the maximum file size ***/
    //if($_FILES['aimage']['size'] < $maxsize )
      //  {
        /*** connect to db ***/
        $formvars['file'] = fread($imgfp, getimagesize($file));

Although using foreach, I got error as Warning: fread() expects parameter 2 to be long, array given in. what's cause of this error? How can I check only images uploaded to site and other files detected by code?

0

2 Answers 2

4

The error is caused by the second parameter of fread() : getimagesize($file)) which returns an array and not a long. getimagesize returns an array(width, height)

Maybe you want to use filesize($file) instead

Sign up to request clarification or add additional context in comments.

Comments

0

From the getimagesize documentation:

Returns an array with up to 7 elements. Not all image types will include the channels and bits elements.

Index 0 and 1 contains respectively the width and the height of the image.

Note: Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases. Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image.

Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

mime is the correspondant MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header:

Example #1 getimagesize() and MIME types

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.