Lost Password?


Go Back   CodeCall Programming Forum > Web Development Forum > PHP Forum

PHP Forum Use this forum to discuss all aspects of PHP Development. PHP is a server-side, cross-platform, HTML embedded scripting language that lets you create dynamic web pages.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-16-2007, 08:40 PM
LHX LHX is offline
Newbie
 
Join Date: Oct 2007
Posts: 2
Rep Power: 0
LHX is on a distinguished road
Default 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 10-16-2007, 09:12 PM
John's Avatar   
John John is offline
Co-Administrator
 
Join Date: Jul 2006
Age: 20
Posts: 3,433
Last Blog:
Google Web Toolkit
Rep Power: 20
John has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond reputeJohn has a reputation beyond repute
Send a message via AIM to John Send a message via MSN to John
Default

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.

PHP 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

__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum | My Blog
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall

Last edited by John; 10-16-2007 at 09:19 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-16-2007, 09:20 PM
LHX LHX is offline
Newbie
 
Join Date: Oct 2007
Posts: 2
Rep Power: 0
LHX is on a distinguished road
Default

awesome

ima test this out tonite



it looks like it makes sense


thanks a lot
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
File Manager Jaan Community Projects 45 08-27-2008 12:11 PM
Windows XP Tricks & Tips!!!!..new ones. pranky Tutorials 9 08-23-2008 04:22 PM
Upload a file jacobronniegeorge Visual Basic Programming 1 09-11-2007 09:40 AM
How to add upload file Kleopatra HTML Programming 3 07-23-2007 09:42 PM
text file manipulations in vb6.0 Ronin_paes Visual Basic Programming 3 06-11-2007 05:54 AM


All times are GMT -5. The time now is 07:29 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 97%

Ads