[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

PHP: Using GetImageSize()

Posted on 2007-08-02
14
Medium Priority
?
919 Views
Last Modified: 2013-12-13
I am trying to get the image width and height:

list($width,$height)=getimagesize($tmpname);

but it only works for files less than 300kb, it will return 0 height and width if the image is greater than 300kb. Any idea why?
0
Comment
Question by:jtcy
12 Comments
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 19622698
please check if the image exists if the size is above 300kb

also try this

<?php

$value = getimagesize($tmpname);

echo($value[3]);
?>
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 19622708
check if the file exists using

if(is_file($tmpname))
{
 echo("File exists");
}
else
{
 echo("File does not exists");
}


also try using mime_content_type function to check if its a valid image.

kiranvj
0
 

Author Comment

by:jtcy
ID: 19622727
But....if file doesnt exist, why would it work for smaller files?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 19622744
are you uploading the file through php, or is the file already exists in the server. If the file exists getimagesize should work for files with any size.
0
 

Author Comment

by:jtcy
ID: 19622795
uploading through php
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 19622839
are u limiting the upload size anywhere in php.ini or in your html form

check for these values in your php.ini

upload_max_filesize
post_max_size

also as i mentioned earlier, please check if the file exists and its a valid image.

kiranvj

0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 19622857
in html also check if there is something like this

<input type="hidden" name="MAX_FILE_SIZE" value="300000" />

0
 
LVL 10

Expert Comment

by:stormist
ID: 19622945
change
In php.ini

    ; Maximum allowed size for uploaded files.
    upload_max_filesize = 2M

0
 

Author Comment

by:jtcy
ID: 19622946
kiranvj, thanks so much! There was <input type="hidden" name="MAX_FILE_SIZE" value="256000">
0
 
LVL 16

Expert Comment

by:Kiran Paul VJ
ID: 19622968
yes that was the problem, so the files above 256000 wont be uploaded.

change that to 1000000, so you can upload files upto 1 MB.
0
 
LVL 4

Accepted Solution

by:
jentulman earned 1000 total points
ID: 19623680
please note that
<input type="hidden" name="MAX_FILE_SIZE" value="256000">

is a purely a guide to the browser and is not guaranteed to limit the upload size, it also will not override PHP's file upload size limit from the PHP.ini so if

<input type="hidden" name="MAX_FILE_SIZE" value="xxxxxxxxx">

is set to a larger value than in the php.ini the file will still upload to the server, but will be rejected by php before the form handling script starts running.

Also with most browsers if the file is larger than

<input type="hidden" name="MAX_FILE_SIZE" value="xxxxxxxxx">

no warning is issued to the user and the form will still submit to the server but the file will not be sent as part of the form (handy to know when you're bug checking, drove me up the wall once upon a time)
0
 
LVL 16

Assisted Solution

by:Kiran Paul VJ
Kiran Paul VJ earned 1000 total points
ID: 19623745
>><input type="hidden" name="MAX_FILE_SIZE" value="xxxxxxxxx">
>>is set to a larger value than in the php.ini the file will still upload to the server, but will be rejected by php before the form handling script starts running.

Yes thats right, its like taking an additional precaution, just like checking a valid email in client and in server. If javascript is disabled in client, the form will be submitted with an invalid email address, so checking is necessary in server also.

>>Also with most browsers if the file is larger than
>><input type="hidden" name="MAX_FILE_SIZE" value="xxxxxxxxx">
>>>no warning is issued to the user and the form will still submit to the server but the file will not be sent as part of the form (handy to know when you're bug checking, drove me up the wall once upon a time)

Yes that was the problem here, jtcy thought the file is in the server and the getimagesize function failed. Actually in most cases I dont assign the MAX_FILE_SIZE

Before calling the getimagesize , the file should be checked if its valid file(is_file) and valid image(mime_content_type).

kiranvj
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question