PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Fri Jul 30, 2004 7:16 pm
I'm creating a file upload page. My server has a restriction of 2MB per file. This is fine, however, I want to inform the user that the reason the file didn't upload was because it is too large. I attempted to solve this by using the following code:
Code: Select all
<?php
foreach($_FILES as $a_file){
//CALCULATE TOTAL FILE SIZES
$total_file_size += $a_file['size'];
}
if($total_file_size>BYTES_IN_ON_MEG*2){
//INFORM USER
}
?>
This is what the $_FILES looks like:
Code: Select all
<?php
Array
(
[new_file_0] => Array
(
[name] => dream car.mpeg
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
[new_file_1] => Array
(
[name] => IMG_0704.jpg
[type] => image/pjpeg
[tmp_name] => /tmp/php0xtsin
[error] => 0
[size] => 883720
)
)
?>
Is there a way for me to determine the file size before the server throws the error?
Also, how can I change the 2 MB limit?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 30, 2004 7:26 pm
[php_man]ini_set[/php_man]() upload_max_filesize and post_max_size
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Fri Jul 30, 2004 7:31 pm
Thanks again Feyd...
Now check this out. It uploaded the file but look at the file size:
Code: Select all
<?php
Array
(
[new_file_0] => Array
(
[name] => dream car.mpeg
[type] => video/mpeg
[tmp_name] => /tmp/phpFFlTgN
[error] => 0
[size] => 0
)
[new_file_1] => Array
(
[name] => IMG_0704.jpg
[type] => image/pjpeg
[tmp_name] => /tmp/phpr5GZqR
[error] => 0
[size] => 883720
)
)
?>
I looked on the server. same thing it had a file size of 0?
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Fri Jul 30, 2004 7:32 pm
I just tried it with a different file...
Didn't work...?
Code: Select all
<?php
Array
(
[new_file_0] => Array
(
[name] => Eraser56Setup.zip
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
[new_file_1] => Array
(
[name] => Untitled-1.gif
[type] => image/gif
[tmp_name] => /tmp/phpyV9l4m
[error] => 0
[size] => 939
)
)
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 30, 2004 7:55 pm
looks like it didn't accept the zip file, as for the mpeg, not sure..
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Fri Jul 30, 2004 7:57 pm
No, it's actually not working at all. The my first "It worked" wasn't true. I just refreshed the page and there it was. however, when i went back and tried it again I got the error.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jul 30, 2004 8:01 pm
hmm.. what's your submitting form look like? Also, what's your new settings for upload_max and post_max?
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Sat Jul 31, 2004 8:07 am
PHPINFO():
Code: Select all
post_max_size 55M 55M
upload_max_filesize 2M 2M
There really isn't anything special with my form, is it just possible that ini_set() didn't work?
Code: Select all
<form action="newreq_process.php" method="post" enctype="multipart/form-data" name="form1">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="100%"> </td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
<td nowrap> <table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td valign="top"><input type="file" name="new_file_0" size=30></td>
</tr>
<tr>
<td valign="top"><input type="file" name="new_file_1" size=30></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit Request"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>