This is a discussion on Re: checking file ext before uploading and more within the alt.comp.lang.php forums, part of the PHP Programming Forums category; > > I'm currently dabbling with a php image upload script. > > I've built in an ok ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
> > I'm currently dabbling with a php image upload script.
> > I've built in an ok extension checker which checks if the file is > > jpg or gif. > > Problem is, this extension checker only works AFTER the file is > > uploaded. I'd like it to work before that so a user wont > > accidentally upload some big wrong file and find out too late. > > > > Any ideas? > > Also, how do I do the same thing with filesize? > > I'd like a message to appear when the file is too big. (say, 150kb) > > > > Is there also a way to check for image dimensions? > > The files which are uploaded will be shown right away on a site and > > I'd prefer not to have huge pictures messing up my layout. For filesize you can use a hidden field: <INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="153600"> where value is the maximum filesize (in bytes). I don't think this produces an error, but it doesn't upload the file. This is easy to get around, so check with PHP too. AFAIK there's no way to check image dimensions in JS, though it's easy to do with PHP (getimagesize) and, if it's too big, adjust the height and width tags to the maximum you want to allow. I've done this on several projects and it usually works great. If you want to get fancy, you could even resize the images with ImageMagick or PHP image functions. Shawn -- Shawn Wilson shawn@glassgiant.com http://www.glassgiant.com |