File upload verification |
02-25-2020, 10:05 AM
(This post was last modified: 02-26-2020, 04:15 AM by GotExx. Edit Reason: unwanted spaces )
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 !
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...ht=isvalid):
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:
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? (02-26-2020, 08:04 AM)zahhar Wrote: That is what I said: you have an issue with accessing uploaded file from CI.
Please Read:
CodeIgniter 4 User Guide - Working With the File What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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.
|
Welcome Guest, Not a member yet? Register Sign In |