/    Sign up×
Community /Pin to ProfileBookmark

PHP file upload max file size problem

Hi ive made a PHP file upload page and im now trying to a put a max file size limit to it

im trying to use:

[code=php]
$filesize = $HTTP_POST_FILES[‘userfile’][‘size’];
$maxfilesize = ‘25000000’;
if ($filesize > $maxfilesize){
header (“Refresh: 3; URL=../fileinfo/selectfile.php”);
?>
<h2 align=”center”>File Size is larger than the limit</h2>

<?php
exit();
}
else if ($filesize < $maxfilesize){

[/code]

but this doesnt seem to do anything as i get the following errors

Warning: fread(): supplied argument is not a valid stream resource in setupuploadfile.php on line 54

Warning: fclose(): supplied argument is not a valid stream resource in setupuploadfile.php on line 56

from this code which is in the following else if statement

[code=php]
$fp = fopen($tmpName, ‘r’);
$filedata = fread($fp, $filesize);
$filedata = addslashes($filedata);
fclose($fp);
[/code]

any ideas?

thanks for any help

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@temp_user123Jul 08.2007 — You're performing a string comparison. Try this:
<i>
</i>$filesize = $HTTP_POST_FILES['userfile']['size'];
$maxfilesize = [COLOR="Red"]25000000[/COLOR];
if ($filesize &gt; $maxfilesize){

or this:
[CODE]
$filesize = [COLOR="red"](integer)[/COLOR]$HTTP_POST_FILES['userfile']['size'];
$maxfilesize = [COLOR="red"]25000000[/COLOR];
if ($filesize > $maxfilesize){[/CODE]
Copy linkTweet thisAlerts:
@cashton2kauthorJul 08.2007 — ta for the help but it still gives the same error, i can echo the filesize so i know that definantly workin to

i really dont get why it wont do it
Copy linkTweet thisAlerts:
@temp_user123Jul 08.2007 — What is the value of both variables?
Copy linkTweet thisAlerts:
@cashton2kauthorJul 08.2007 — wait sorry i cant echo the filesize, it doesnt have a value when that error comes up, it does when i try small files though

im guessin thats why the if doesnt work then lol
Copy linkTweet thisAlerts:
@cashton2kauthorJul 08.2007 — whats causing it break when i send big files then?
Copy linkTweet thisAlerts:
@temp_user123Jul 09.2007 — I'd say the server (or PHP), itself, is rejecting the file(s) because they are too big or time out because they take too long to upload. Be sure to check that the file was actually uploaded:

$_FILES["name"]["size"] > 0
Copy linkTweet thisAlerts:
@cashton2kauthorJul 09.2007 — i 6.5mb file uploaded fine but an 8mb one failed

i changed the php.ini max file upload size to 30M when i started, should anything else be changed?
Copy linkTweet thisAlerts:
@MrCoderJul 09.2007 — i 6.5mb file uploaded fine but an 8mb one failed

i changed the php.ini max file upload size to 30M when i started, should anything else be changed?[/QUOTE]


Did you restart apache?
Copy linkTweet thisAlerts:
@temp_user123Jul 09.2007 — There is a time-out somewhere that can affect whether large uploads succeed or not.
Copy linkTweet thisAlerts:
@cashton2kauthorJul 09.2007 — max execution time?

plus im guessing memory_limit shud be higher than the default 8M if i want bigger files than that?
×

Success!

Help @cashton2k spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...