Reputation: 57196
How can I get the file's name when it is too large?
I can get its length using $_SERVER['CONTENT_LENGTH']
but what about its name?
// check that post_max_size has not been reached
// convert_to_bytes is the function turn `5M` to bytes because $_SERVER['CONTENT_LENGTH'] is in bytes.
if (isset($_SERVER['CONTENT_LENGTH'])
&& (int) $_SERVER['CONTENT_LENGTH'] > convert_to_bytes(ini_get('post_max_size')))
{
// ... with your logic
throw new Exception('File too large!');
}
for instance, if I upload an mp3,
very-large.mp3 (size 11MB)
I would like to get its name which is very-large.mp3
is it possible? Or do I have to use javascript?
NOTE:
You will get
Array()
with $_FILES
when the file is too large.
So then you can't get $_FILES[file]["name"]
Upvotes: 0
Views: 64
Reputation: 43479
So if you have <input type="file" name="userFile"/>
than you use it's name to get name from $_FILES
global variable: echo "File {$_FILES['userFile']['name']} is too big.";
Upvotes: 1