Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Using PEAR's HTTP_Upload to manage MAX FILE SIZE
Old 09-22-2010, 09:01 PM Using PEAR's HTTP_Upload to manage MAX FILE SIZE
Designer-geek's Avatar
Novice Talker

Posts: 6
Name: Fiona
Location: rural australia
Trades: 0
Do you use HTTP_Upload to validate file size? I am after some example code to see how I can validate the file size AND type using the PEAR package. I can see the code in PEAR's Upload.php file which checks and displays the error message for a large file size but I can't figure out how to utilise it, here is my code which checks for a valid file type successfully but fails to validate the size.

Code:
 
if (isset($_FILES['f'])) {
 
// Validate the type. 
$allowedExtensions = array ('application/pdf', 'application/msword', 'application/rtf', 'text/plain');
if (in_array($_FILES['f']['type'], $allowedExtensions)) {
 
// Move the file over.
require_once('../Includes/Upload.php');
 
$upload = new http_upload('en');
$file = $upload->getFiles('f');
if (PEAR::isError($file)) {
die ($file->getMessage());
}
if ($file->isValid()) {
$file->setName('uniq');
$dest_dir = 'uploads';
$n = $file->getProp('size');
 
// validate the file size (THIS DOESN'T WORK)
if ($_FILES['f']['size'] > ($_POST['MAX_FILE_SIZE'])){ 
//$errors[] = 'File size exceeded. Must be less than 3mb.';
$echo = 'File size exceeded. Must be less than 3mb.';
}
There is a section built into PEAR which ckecks the file size and creates an error message, alas my skill set isn't up to transalting this code to utilize it, here it is...
Designer-geek is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-23-2010, 02:42 AM Re: Using PEAR's HTTP_Upload to manage MAX FILE SIZE
Designer-geek's Avatar
Novice Talker

Posts: 6
Name: Fiona
Location: rural australia
Trades: 0
When in doubt start from scratch, please don't bother replying to my post
Designer-geek is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Using PEAR's HTTP_Upload to manage MAX FILE SIZE
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.73659 seconds with 12 queries