c_pattle Posted January 12, 2012 Share Posted January 12, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/254876-codeigniter-cant-get-file-input-value/ Share on other sites More sharing options...
sKunKbad Posted January 17, 2012 Share Posted January 17, 2012 Why not just use the CI Uploader class? Quote Link to comment https://forums.phpfreaks.com/topic/254876-codeigniter-cant-get-file-input-value/#findComment-1308438 Share on other sites More sharing options...
deals Posted January 17, 2012 Share Posted January 17, 2012 try this: $petPhoto = $_FILES['petPhoto']['name']; Quote Link to comment https://forums.phpfreaks.com/topic/254876-codeigniter-cant-get-file-input-value/#findComment-1308584 Share on other sites More sharing options...
JacobCMarshall Posted February 6, 2012 Share Posted February 6, 2012 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" Quote Link to comment https://forums.phpfreaks.com/topic/254876-codeigniter-cant-get-file-input-value/#findComment-1315042 Share on other sites More sharing options...
ME_php Fresher Posted February 21, 2012 Share Posted February 21, 2012 first you need to know you are using the input type file , so be sure to use the enctype , second use $_FILES or the uploader class of Codeigniter. Your problem is over. Quote Link to comment https://forums.phpfreaks.com/topic/254876-codeigniter-cant-get-file-input-value/#findComment-1319514 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.