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
help setting max upload size needed!
Old 10-20-2007, 03:40 PM help setting max upload size needed!
HTML_kid's Avatar
Novice Talker

Posts: 6
Name: Frank Mazzarella
Trades: 0
can anobody help me edit this code to block uploads bigger than 8M

[PHP]<?php
if(!isset($_POST['upload'])) {
?>
<form name="upload" enctype="multipart/form-data" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="file" name="file" size="13" value="">
<br /><input type="submit" name="upload" value="Upload">
</form>
<?php
} else {
$uploaddir = '/home/xboxlead/public_html/nav/upload/temp/';
$filename = $_FILES['file']['name'];
$tmpname_file = $_FILES['file']['tmp_name'];
$date_file = date(imdy);

move_uploaded_file($tmpname_file, "$uploaddir$date_file$filename");
echo "Successful";
}
?>[/
PHP]
__________________
$must = $_GET['life'];
HTML_kid is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-20-2007, 05:36 PM Re: help setting max upload size needed!
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
This if statment should catch any files larger than 8MB

PHP Code:
if(filesize($filename) > 8388608)
{
    
//do something here

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 10-20-2007, 06:58 PM Re: help setting max upload size needed!
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Edit your php configuration, there should be an upload limit in there.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 10-20-2007, 07:31 PM Re: help setting max upload size needed!
HTML_kid's Avatar
Novice Talker

Posts: 6
Name: Frank Mazzarella
Trades: 0
i do have an upload limit there, i buy hosting and they have it set at 8.

what happens is when i try to upload more than 8M, the page refreshes after some of it uploads instead of saying that the file is too big, is it possible to have the size checked before the actual upload process begins?

thanks in advance!
__________________
$must = $_GET['life'];
HTML_kid is offline
Reply With Quote
View Public Profile
 
Old 10-20-2007, 08:42 PM Re: help setting max upload size needed!
rion's Avatar
Experienced Talker

Posts: 31
Name: Rion
Location: Portland, Oregon
Trades: 0
$limit_size = 8388608;
$file_size=$HTTP_POST_FILES['form_file_id_name']['size'];
f($file_size >= $limit_size){
echo "Your file size is over limit<BR>";
echo "Your file size = ".$file_size;
echo " K";
echo "<BR>File size limit = 8MB";
}
else {

#continue_uploading_code_here

}

change the form_file_id_name to the id/name from your form.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Last edited by rion; 10-20-2007 at 08:45 PM..
rion is offline
Reply With Quote
View Public Profile Visit rion's homepage!
 
Old 10-20-2007, 09:31 PM Re: help setting max upload size needed!
HTML_kid's Avatar
Novice Talker

Posts: 6
Name: Frank Mazzarella
Trades: 0
Quote:
Originally Posted by rion View Post
$limit_size = 8388608;
$file_size=$HTTP_POST_FILES['form_file_id_name']['size'];
f($file_size >= $limit_size){
echo "Your file size is over limit<BR>";
echo "Your file size = ".$file_size;
echo " K";
echo "<BR>File size limit = 8MB";
}
else {

#continue_uploading_code_here

}

change the form_file_id_name to the id/name from your form.
Parse error: parse error, unexpected '{' on line 19 [ f($file_size >= $limit_size){ ]
__________________
$must = $_GET['life'];

Last edited by HTML_kid; 10-20-2007 at 09:33 PM..
HTML_kid is offline
Reply With Quote
View Public Profile
 
Old 10-20-2007, 09:44 PM Re: help setting max upload size needed!
HTML_kid's Avatar
Novice Talker

Posts: 6
Name: Frank Mazzarella
Trades: 0
ok i fixed the error,i changed the f to if, but the script is still trying to upload the file before displayin the error
__________________
$must = $_GET['life'];
HTML_kid is offline
Reply With Quote
View Public Profile
 
Old 10-20-2007, 11:41 PM Re: help setting max upload size needed!
rion's Avatar
Experienced Talker

Posts: 31
Name: Rion
Location: Portland, Oregon
Trades: 0
sorry about that typo....ok....looks like you are going to need to use some javascript to check the filesize...let me find something and i'll post again shortly
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
rion is offline
Reply With Quote
View Public Profile Visit rion's homepage!
 
Old 10-21-2007, 12:03 AM Re: help setting max upload size needed!
rion's Avatar
Experienced Talker

Posts: 31
Name: Rion
Location: Portland, Oregon
Trades: 0
ok apparently it's not possible to do using javascript either. The only thing I can think of is to use an output buffer during the upload. Or limit the size to less than your hosts limit of 8MB. Set it to 7.5 maybe and see if it dies.

If you don't have
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
put that before the file input element.

While I'm at it I'll just post the php.net page related to handling uploaded files.

http://www.php.net/manual/en/features.file-upload.php
I hope this helps.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
rion is offline
Reply With Quote
View Public Profile Visit rion's homepage!
 
Old 10-25-2007, 04:11 AM Re: help setting max upload size needed!
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Manual, Chapter 18. Handling file uploads
Error Messages Explained
"Since PHP 4.2.0, PHP returns an appropriate error code along with the file array. The error code can be found in the ['error'] segment of the file array that is created during the file upload by PHP. In otherwords, the error might be found in $_FILES['userfile']['error'].
...
UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
..."

This means that you can easily detect in your script whether the uploaded file exceeded the filesize allowed in php.ini.
Code:
if (!empty($_FILES) && $_FILES['myfile']['error'] == 1) {
   // do something to tell user that a file is too large
}
else {
   // do anything else
}
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to help setting max upload size needed!
 

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.54071 seconds with 12 queries