Re: Trapping for PDF Type and file size in a UPLOAD form...

From: Date: Thu, 29 Jul 2010 17:25:33 +0000
Subject: Re: Trapping for PDF Type and file size in a UPLOAD form...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-307219@lists.php.net to get a copy of this message
On Jul 29, 2010, at 12:50 PM, Don Wieland wrote: > I am trying to create an UPLOAD form and need to figure a way to only allow PDF files to be > selected. Something like: > > <html> > <body> > <form enctype="multipart/form-data" action="upload.php" > method="post"> > <input type="hidden" name="MAX_FILE_SIZE" value="1000000" > accept="application/pdf" /> > Choose a file to upload: <input name="uploaded_file" type="file" /> > <input type="submit" value="Upload" /> > </form> > </body> > </html> > > It is documented online that I can pass a parameter ACCEPT="applaction/pdf", BUT it > is not recognized in most browsers. > > It was suggested by someone that I could trap for this using a JAVASCRIPT. Can someone assist > with a snippet of javascript code to trap for this for me? This is the end result I need: > > If the user selects a file that IS NOT a PDF file, display an javascript alert "You can > only upload PDF files. Please try again." > > If the user selects a PDF file greater than 1MB, display an javascript alert "File uploads > may not exceed 1M in file size. Please try again." > > I appreciate any help that can be offered. Thanks in advanced! > > Don Wieland > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > Don- Remember that anything submitted by the client can be spoofed or faked. Ensure that your PHP script accounts for Javascript being disabled. Past that, I'm sure you can get results from somewhere like Stackoverflow.com instead of a PHP mailing list. Thanks, -Josh

« previous php.general (#307219) next »