1. ## Width/Height of an Uploaded Image?

Hi all,

On a site I am developing, there is an area for users to upload an image of themselves. The actual upload code works, but the code I have in place is not grabbing the width/height of the image (to make sure it doesn't exceed the maximum dimensions). The form code is as follows:

Code:
<form method="POST" action="photo_admin.php" enctype="multipart/form-data">
<input type="hidden" name="photo" value="main" />
<input type="file" name="main">
<input type="submit" name="Submit" value="Upload New Image" class="flatButton" />
</form>
Further down the page, I think check to see whether $_POST['photo'] == 'main' and if so, execute the following code: PHP Code: $imgData = getimagesize($_FILES['main']['tmp_name']);$imgWidth = $imgData[0];$imgHeight = $imgData[1]; if (($imgWidth > 800) || ($imgHeight > 600)) { echo ('<span class="error">Uploaded images must not exceed 800x600 pixels in size.</span>' . BR . BR . 'Click <a href="photo_admin.php">here</a> to go back and try again.'); } else { // Upload image }  Any help would be much appreciated. -Will 2. Are BR constants you declared in some place of the files?. you could verify if the file has been uploaded with is_uploaded_file($_FILES['main']['tmp_name']) before
doing any other operations

3. Thanks hidran,

I added the is_uploaded_file line and it does recognise it as an uploaded file (plus this is used later on to upload the image so it must be correct). Before the getimagesize line, I added: error_reporting(E_ALL) which returned the following error:

Warning: getimagesize(): Unable to access C:\WINDOWS\TEMP\phpBDB6.tmp in E:\USERS\path\to\file on line 187 Warning: getimagesize(C:\WINDOWS\TEMP\phpBDB6.tmp): failed to open stream: No such file or directory

Any ideas? I'm kinda stumped.

-Will

4. Afternoon Will, I am pretty sure you cant use getimagesize until the image is on the server. So until the file has fully uploaded you cant get the image dimentions.

What you can do is either resize it or delete it if it doesn't conform.

5. Hi spike, long time no see

Instead I've imposed a file size restriction using \$_FILES['image]['size']. Given the situation it seems more logical than using height/width restrictions anyway.

Thanks for the help, spike and hidran.

-Will

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•