Closed Thread
Results 1 to 3 of 3

Thread: Customizing a File Upload - Please Help

  1. #1
    LHX
    LHX is offline Newbie
    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0

    Customizing a File Upload - Please Help

    Hello yall

    I'm sure this must be a basic question but I'm still getting familiar with all this PHP stuff.

    Basically, what I am looking to do is to put together an image file-upload system which has a limit on the height and width that the user can upload.

    I have followed along with all the info contained at the W3schools site:
    PHP File Upload

    I understand that I will have to create my own function for this, but I don't quite know how to go about doing it.

    I found some sites that seem to have a solution, but they don't seem to be geared to my level of beginner.

    For instance - I found a site that seemed to describe how to do this (PHP Upload Images), but I do not understand these lines:

    Code:
    $my_uploader->max_image_size(150, 150); // max_image_size($width, $height)
    Code:
     /**
    * void max_image_size ( int width, int height );
    *
    * Sets the maximum pixel dimensions. Will only be checked if the
    * uploaded file is an image
    *
    * @param width (int) maximum pixel width of image uploads
    * @param height (int) maximum pixel height of image uploads
    *
    */
    function max_image_size($width, $height){
    $this->max_image_width = (int) $width;
    $this->max_image_height = (int) $height;
    }
    If somebody could tell me briefly what I would need to add to the info from W3 in order to set this upload restriction, I would really appreciate it.

    Conceptually, I understand what needs to be done: compare the width and height of the uploaded image to pre-defined variables, but I do not know how to execute this.

    Any help is appreciated.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Location
    Amherst, New York, United States
    Posts
    6,277
    Blog Entries
    26
    Rep Power
    20
    The code you posted above is object oriented, and most beginners dont understand the syntax as they are use to procedural programming. Essentially the lines you posted above don't do anything but set the maximum width and height allowed, it doesn't actually check if the image that is intended to be uploaded is within the constraints you set.

    Use getimagesize() on your temporary file. For an example, check out my PHP: Upload Class. This class is object oriented so I'm sure you won't understand most of it, however this is what is really of your concern.

    Code:
    $size = @getimagesize($_FILES["file"]["tmp_name"]);
    $width $size[0];
    $height $size[1];
    if(
    $width 150) {
    die(
    "The width of the image must be less than 150px");
    } else if(
    $height 150) {
    die(
    "The height of the image must be less than 150px");
    } else {
    //the size of the image is good

    Last edited by John; 10-16-2007 at 06:19 PM.

  4. #3
    LHX
    LHX is offline Newbie
    Join Date
    Oct 2007
    Posts
    2
    Rep Power
    0
    awesome

    ima test this out tonite



    it looks like it makes sense


    thanks a lot

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. upload file
    By leeyo in forum JavaScript and CSS
    Replies: 4
    Last Post: 07-19-2010, 10:03 AM
  2. Upload multiple file
    By claudiu in forum PHP Development
    Replies: 6
    Last Post: 01-23-2010, 07:20 AM
  3. Upload a file
    By jacobronniegeorge in forum Visual Basic Programming
    Replies: 1
    Last Post: 09-11-2007, 06:40 AM
  4. How to add upload file
    By Kleopatra in forum HTML Programming
    Replies: 3
    Last Post: 07-23-2007, 06:42 PM

Tags for this Thread

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