By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,965 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,965 IT Pros & Developers. It's quick & easy.

image uploading validations

P: 5
In my web site there are 5 image uploading sections. I want to validate them by size,width,height and type.can any one help me to cover this task by PHP.
Sep 11 '12 #1

✓ answered by niheel

to get the filesize of the images you can use the php function filesize
Expand|Select|Wrap|Line Numbers
  1. $filename = 'somefile.txt';
  2. $filesize = filesize($filename);
  3.  
filesize will return the size of the file in bytes

to get the height, width and type you should use php function getimagesize
Expand|Select|Wrap|Line Numbers
  1. $size = getimagesize($filename);
returns an array size with the following information
0 = height
1 = width
2 = image type
3 = height & width in html format for img tag

Share this Question
Share on Google+
2 Replies


Expert Mod 100+
P: 2,327
to get the filesize of the images you can use the php function filesize
Expand|Select|Wrap|Line Numbers
  1. $filename = 'somefile.txt';
  2. $filesize = filesize($filename);
  3.  
filesize will return the size of the file in bytes

to get the height, width and type you should use php function getimagesize
Expand|Select|Wrap|Line Numbers
  1. $size = getimagesize($filename);
returns an array size with the following information
0 = height
1 = width
2 = image type
3 = height & width in html format for img tag
Sep 11 '12 #2

P: 5
Great thanks for your answer.
Sep 15 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.