8.4+: File upload error: file too large but it's not
Permalink
I'm uploading a 200 kB file with this:
it throws an error: "Uploaded file is too large. The current value of upload_max_filesize is 2M". But the file is only 200 kB! Why does that throw the exception?
BTW, the photo does get uploaded into the File Manager. What's wrong with the file being an instance of the Version?
$service = $this->app->make('helper/security'); if (is_uploaded_file($photo)) { $importer = new Importer(); $photo = $_FILES['photo']['tmp_name']; $photo_name = $service->sanitizeString(mb_strtolower($_FILES['photo']['name'])); $file = $importer->import($photo, $photo_name); if ($file instanceof Version) { ... } else { $e->add(Importer::getErrorMessage($file)); // <- ERROR HERE } } else { $e->add($_FILES['photo']['error']);
Viewing 15 lines of 16 lines. View entire code block.
it throws an error: "Uploaded file is too large. The current value of upload_max_filesize is 2M". But the file is only 200 kB! Why does that throw the exception?
BTW, the photo does get uploaded into the File Manager. What's wrong with the file being an instance of the Version?
Hey @linuxoid. Just as an FYI, if this is something for the PRB, $_FILES will not fly. You should get it from the active request using $request->files the same way you do $request->request for $_POST and $request->query for $_GET
Hi! Yes, it is for PRB. Thank you very much for reminding me.
Can't find the request info. What would be an equivalent of $_FILES['photo']['name']? $this->request->files['photo']['name']? Or is the file itself in the $this->request->files->get('photo')? How do I get the rest of file info, e.g. name etc.?
Yes you use
What you get back is either an array if several file upload inputs with the same name exist or a vendor\symfony\http-foundation\File\UploadedFile object. If it's an array, it is an array of UploadedFile objects
Check the function handleUpload() in the file concrete\controllers\backend\file.php to see how they grab the information. It will also show you how to get the path to the file and other things.
Anyway, once you have that UploadedFile object you have functions to get the file name, original file name, extension, mime type from the object
$this->request->files->get('photo')
What you get back is either an array if several file upload inputs with the same name exist or a vendor\symfony\http-foundation\File\UploadedFile object. If it's an array, it is an array of UploadedFile objects
Check the function handleUpload() in the file concrete\controllers\backend\file.php to see how they grab the information. It will also show you how to get the path to the file and other things.
Anyway, once you have that UploadedFile object you have functions to get the file name, original file name, extension, mime type from the object
There's nothing in that file about getting the file name, type, size. I only see they get paths, that's it. I've checked the Symphony's UploadedFile, I guess it's the getClientOriginalName etc.
BTW I don't understand why I can't use the $_FILES if it's already. What's the reason?
BTW I don't understand why I can't use the $_FILES if it's already. What's the reason?
Sprry I wasn't clearer. The file file.php is just an example to see how to grab the object and also its path. For the file information such as name, extension... They are all from the class vendor\symfony\http-foundation\File\UploadedFile which is what you get back.
So in file.php look to see how they deal with multiple or single file and stuff like that. And then for each uploaded file you get back a vendor\symfony\http-foundation\File\UploadedFile object so look inside that class to see the functions available to you
So in file.php look to see how they deal with multiple or single file and stuff like that. And then for each uploaded file you get back a vendor\symfony\http-foundation\File\UploadedFile object so look inside that class to see the functions available to you
$photo = $_FILES['photo']['tmp_name']; $photo_name = mb_strtolower($_FILES['photo']['name']); $photo_size = $_FILES['photo']['size']; $photo_type = pathinfo($photo_name, PATHINFO_EXTENSION);
equivalent:
$files = $this->request->files; $photo = $files->get('photo'); $photo_name = mb_strtolower($photo->getClientOriginalName()); $photo_size = $photo->getClientSize(); $photo_type = $photo->getClientOriginalExtension();
yep, looks good.
The Documentation pagehttps://documentation.concrete5.org/developers/working-with-files-an... in the section Handling Permissions has the error: