Jump to content

Codeigniter can't get file input value


c_pattle

Recommended Posts

I have a form with a file input field to allow users to upload image files. 

 

<input id="petPhoto" type="file" value="photo" name="petPhoto">

 

The problem I'm having is that I can't get the value in this field when the form is submitted (e.g images/fileimage.jpg). 

 

In my controller I have the following line to try to get the value but when I do a var dump on it, it just returns false. 

 

$petPhoto = $this->input->post('petPhoto');

 

Does anyone know what I'm doing wrong?

Link to comment
Share on other sites

  • 3 weeks later...

Use what 'deals' said. Just because you're using a framework, doesn't always mean you need to use all the functions built into it. Sometimes using the core PHP functions can be much easier than the frameworks built in functions.

 

What is wrong with your code is that you're trying to access the $_POST array, when really you need to be accessing the $_FILES array. Read through the related section on the official CodeIgniter user guide here.

 

EDIT: As of yet, I have not found a way of accessing the $_FILES array through the CodeIgniter functions/classes, however I will look more into that as I am unsure if that is correct or not.

 

EDIT x2: Also make sure your form tag includes the enctype attribute, it should look something like this:

enctype="multipart/form-data"

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.