Jump to content

Customizing a File Upload - Please Help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
LHX

LHX

    Newbie

  • Members
  • Pip
  • 2 posts
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:

$my_uploader->max_image_size(150, 150); // max_image_size($width, $height)

 /**
* 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
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
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 http://forum.codecal...load-class.html. 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.

$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
}


#3
LHX

LHX

    Newbie

  • Members
  • Pip
  • 2 posts
awesome

ima test this out tonite



it looks like it makes sense


thanks a lot