1,105,556 Community Members

file upload to large, $_POST/$_FILE empty so cant throw error

Member Avatar
OnIIcE
Light Poster
34 posts since Dec 2007
Reputation Points: -1 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi guys,

im trying to upload files to my script and have hit an anoying problem.

if the file is bigger than what I allow in in my php.ini config, the $_POST and $_FILE comes through empty - and I cant check that there's been a post to then check the $_FILE error being to big.

How can I check that its been posted and is to big, so I can send a message to the user informing them of this?!

Thanks!

Member Avatar
fobos
Posting Whiz
351 posts since Feb 2009
Reputation Points: 19 [?]
Q&As Helped to Solve: 68 [?]
Skill Endorsements: 3 [?]
 
0
 

Why dont you just put an upload limit, that way you dont have to worry about a file being too big.

<?php
if ($_FILES["file"]["size"] > 20000) { // if file is over 20 kb, throw error
  echo "Error: " . $_FILES["file"]["error"] . "<br />";
} else {
  //Code
}
?>
Member Avatar
OnIIcE
Light Poster
34 posts since Dec 2007
Reputation Points: -1 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

i would do a check like that, but the $_FILES variable is empty, so i cannot check it as youve shown!

Member Avatar
fobos
Posting Whiz
351 posts since Feb 2009
Reputation Points: 19 [?]
Q&As Helped to Solve: 68 [?]
Skill Endorsements: 3 [?]
 
0
 

show me your code

Member Avatar
LethargicCoder
Junior Poster in Training
54 posts since Apr 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
0
 
Member Avatar
veedeoo
Veteran Poster
1,017 posts since Oct 2011
Reputation Points: 314 [?]
Q&As Helped to Solve: 166 [?]
Skill Endorsements: 17 [?]
 
0
 

Hi,

PHP will not be able to check the file size before the file upload is executed. There is no way you can detect on the desktop's directory. File upload has to occur first, and then the script checks on the file size..

There is another way of doing this.. it is called flash dependency class.. try searching filereference class, externalReference class... that should work for what you are trying to achieved.

If you use the flash dependency, you must use this responsibly and only for the purpose of serving the file size detection function and upload function. This can throw many security holes on the desktop side.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: