SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    My portfolio: lemonadeX.net
    XHTML/CSS/PHP coder for hire

  2. #2
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Italy,turin
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    hidran
    www.photoviaggi.com
    pictures from around the world

  3. #3
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    My portfolio: lemonadeX.net
    XHTML/CSS/PHP coder for hire

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    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.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Evangelist LemoNade's Avatar
    Join Date
    Aug 2005
    Location
    Southampton, UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    My portfolio: lemonadeX.net
    XHTML/CSS/PHP coder for hire


Bookmarks

Posting Permissions

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