Jump to content

Trying to Catch an Invalid Image File


brent123456

Recommended Posts

I am having trouble trying to get and invalid image. I made a text file then named it test.jpg to test with. I can't seem to find a way to check it i have tried at a lot of test and they fail. I have tried

if (getimagesize($_FILES['image']['name'])) { 

that gives me..

Warning: getimagesize(test.jpg) [function.getimagesize]: failed to open stream: No such file or directory in

I have tried checking

$_FILES['image']['type']

 

Could someone help me out please.

Link to comment
Share on other sites

 

imagealphablending()  you may try to use this function to check the image file,  and if the result is FALSE.  Most likely the source is not a proper image file.

 

imagealphablending() allows for two different modes of drawing on truecolor images. In blending mode, the alpha channel component of the color supplied to all drawing function, such as imagesetpixel() determines how much of the underlying color should be allowed to shine through. As a result, gd automatically blends the existing color at that point with the drawing color, and stores the result in the image. The resulting pixel is opaque. In non-blending mode, the drawing color is copied literally with its alpha channel information, replacing the destination pixel. Blending mode is not available when drawing on palette images. If blendmode is TRUE, then blending mode is enabled, otherwise disabled. Returns TRUE on success or FALSE on failure.

Link to comment
Share on other sites

Warning: Wrong parameter count for imagealphablending() in C:\myxampp\xampp\htdocs\seedswaps\site_pages\includes\processaddseeds.php on line 133

 

I tried using the imagealphablending like this and got the warning above.

 

 $test = imagealphablending($_FILES['image']['name']);
                        echo $test;

 

I am having a hard time trying to figure this one out.

Link to comment
Share on other sites

I am not sure if this is the correct way but I couldn't find anything that would not check the file and give me a warning error so i just suppressed the error with an '@' before

@getimagesize($_FILES['image']['name']

so it will still do the check but not give me a warning and full pass discloser. If anyone knows a better way to handle it I would enjoy hearing it. Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.