Welcome Guest, Not a member yet? Register   Sign In
Get uploaded file data in CI 4
#1

In Codeigniter 3, $this->upload->data(); does it. In documentation of CI 4, I found some functions for getting specific uploaded file data like, getName(), getClientName(), getClientMimeType() etc. But how can I get all the uploaded file data at once like CI 3?

I am using $file->store(); to upload file.

Thanks in advance.
"Who thinks in code"
Perfectly describes who I am
mbparvez.me
Reply
#2

All of the parameters are in the $_FILES[] array.

PHP Code:
$file_name     $_FILES["photo"]["name"]; 
$file_type     $_FILES["photo"]["type"]; 
$file_size     $_FILES["photo"]["size"]; 
$file_tmp_name $_FILES["photo"]["tmp_name"]; 
$file_error    $_FILES["photo"]["error"]; 

Where photo would be the input name.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(09-18-2019, 03:50 AM)InsiteFX Wrote: All of the parameters are in the $_FILES[] array.

PHP Code:
$file_name     $_FILES["photo"]["name"]; 
$file_type     $_FILES["photo"]["type"]; 
$file_size     $_FILES["photo"]["size"]; 
$file_tmp_name $_FILES["photo"]["tmp_name"]; 
$file_error    $_FILES["photo"]["error"]; 

Where photo would be the input name.

Thank you.

But how to do this using CI4?
"Who thinks in code"
Perfectly describes who I am
mbparvez.me
Reply
#4

(This post was last modified: 07-15-2020, 01:28 AM by captain-sensible.)

if you have a view which includes a form something like:
Code:
<?= form_open_multipart('newblog'); ?>
                            <div class="form-group">
                <input type="file" name="userfile" size="20" />
                
                              </div>
                               <div class="form-group">
               <input type="submit" class ="btn-success" value="submit" />
               </div>
                           </form>

Code:
then to get info on image that was navigated to used when form was submitted via POST
$file = $this->request->getFile('userfile');
        
                $name= $file->getName();

                $tempfile = $file->getTempName();
                           $type = $file->getMimeType();
                       $kbSize=      $file->getSize('kb');
//try this with a form and echo out $name and $tempfile to see what it gives you

see section starting quater down

https://codeigniter4.github.io/CodeIgnit...files.html
Reply




Theme © iAndrew 2016 - Forum software by © MyBB