Bluehost.com Web Hosting $6.95

Re: checking file ext before uploading and more

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 ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-11-2003
Shawn Wilson
 
Posts: n/a
Default Re: checking file ext before uploading and more

> > 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
Reply With Quote
Reply
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:21 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0