![]() |
File upload verification - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: File upload verification (/showthread.php?tid=75599) |
File upload verification - GotExx - 02-25-2020 Hi all, I'm trying to set up a check for uploading a file. CI keeps returning the error: Archive file is not a valid uploaded file. Also, I am not sure that CI recognizes gzip files as application/x-gzip The PHP function mime_content_type returns application/x-gzip to me. My controller function PHP Code: public function uploadBackup() My HTML Code: <?= form_open(route_to('uploadBackup'), 'class="form-inline"'); ?> Thank's ! RE: File upload verification - zahhar - 02-25-2020 Hi GotExx, I run your code and it works fine for me. If you get error message saying "Archive file is not a valid uploaded file." it means uploaded[archiveFile] validation fails. It has nothing to do with MIME types, as then it would tell you "Archive file does not have a valid mime type". You can check it yourself if you first remove uploaded[archiveFile] validation from your code and run it - it should pass OK. Then change mime_in[archiveFile,application/x-gzip] into mime_in[archiveFile,application/anything] and you will see "Archive file does not have a valid mime type". error message. So you have to analyze why uploaded[archiveFile] validation fails. This validation rule calls isValid() function that will fail if anything from the following list occurs (as per official docs, https://codeigniter4.github.io/userguide/libraries/uploaded_files.html?highlight=isvalid):
RE: File upload verification - GotExx - 02-26-2020 Hi zahhar, Thank's for your reply. Ok I've increase the upload_max_filesize in php.ini to 1G but when i remove the first rule uploaded[archiveFile], i simply get the second error : Archive file does not have a valid file extension by ext_in[archiveFile,gzip] rule. When i also remove the mime_in[archiveFile,application/x-gzip] rule i get the third error: Archive file does not have a valid mime type. I've also try to remove all the rules and only put this: PHP Code: $validation->setRule('archiveFile', 'Archive file', 'is_image[archiveFile]'); For information this is my configuration:
RE: File upload verification - zahhar - 02-26-2020 That is what I said: you have an issue with accessing uploaded file from CI. Your code is fine, and there is no issue in CI4-rc3 (however, you might want to upgrade to stable version). I would suggest you to contact your hosting provider if you have a virtual managed hosting, or if you are self-managed, then address one by one each and every item from the list. Most probably one of those 2 prevents you: [ ] The file could not be written on disk. [ ] File could not be uploaded: missing temporary directory. Also, - what yoyu are using in between of PHP and CI - Apache? Nginx? Anything else? - do you run PHP in safe_mode, as FCGI, or? RE: File upload verification - 12idho - 09-01-2021 (02-26-2020, 08:04 AM)zahhar Wrote: That is what I said: you have an issue with accessing uploaded file from CI. RE: File upload verification - InsiteFX - 09-02-2021 Please Read: CodeIgniter 4 User Guide - Working With the File RE: File upload verification - mdahmke - 06-15-2023 I ran into the same problem, getting the "not a valid file" error. After checking folder permissions, max upload size, etc, I tested file upload to the target folder using a stand-alone script with the native PHP function and it worked. Next, I inserted that code in the Controller in place of the CI upload sample code and it worked. I still haven't been able to determine why the CI4 code fails. |