Page 1 of 1
imagex/imagesy with $_FILE??
Posted: Sun Feb 13, 2011 9:27 am
by psychotomus
I am having trouble getting the imagesx and imagesy with an image from memory.
always returning true no matter what...

any work-a-round. I don't feel like uploading the image then deleting if its to big.
Code: Select all
if(imagesx($_FILES["file"]["tmp_name"]) > AVATAR_MAX_WIDTH || imagesy($_FILES["file"]["tmp_name"]) > AVATAR_MAX_HEIGHT)
Re: imagex/imagesy with $_FILE??
Posted: Sun Feb 13, 2011 4:11 pm
by McInfo
psychotomus wrote:I don't feel like uploading the image then deleting if [it's too] big.
By the time $_FILES is populated, the file has already been uploaded.
Notice that these functions expect an image resource, not a file name string.
PHP Manual wrote:int imagesx ( resource $image )
int imagesy ( resource $image )
If the dimensions of the image matter, do some research to find a reasonable maximum file size for an image with the format and number of pixels you expect. To validate an uploaded image, first test the file to confirm that it does not exceed the maximum file size. Then create an image resource from the file and test the dimensions.
Re: imagex/imagesy with $_FILE??
Posted: Fri Feb 18, 2011 7:23 pm
by McInfo
I was just reminded of
getimagesize(), which is preferable to creating an image resource in this situation.