1

It is my first time to use codeigniter in building my school project.

Let me go straight.

I can get my POST request except for the form_upload();

This is my sample FORM:

<?php
echo form_open('admin/test_upload');
 echo form_input(array('name' => 'title'));?><br/><?
 echo form_upload(array('name' => 'file'));
 echo form_submit(array('name' => 'submit', 'value' => 'submit'));
echo form_close();
?>

This is my CONTROLLER:

function test_upload(){
 $data['header'] = "TEST UPLOAD";
 var_dump($_POST) ; //basically, this is function echoes back the post array.
 $this->load->view('admin/dashboard_view', $data);
}

This is the Output

array(2) {
["title"]=>
string(3) "asd"
["submit"]=>
string(6) "submit"
}
//The ["file"] is missing.... wHAT!?>

Can someone help me out?

gen_Eric
228k42 gold badges304 silver badges343 bronze badges
asked Aug 14, 2012 at 13:42
0

2 Answers 2

2

File uploads need to have an enctype="multipart/form-data" in their form tag, so you should be using this to open the form:

echo form_open_multipart('admin/test_upload');

Also, as the others have mentioned, the uploaded files will be in $_FILES instead of $_POST.

answered Aug 14, 2012 at 13:45
Sign up to request clarification or add additional context in comments.

2 Comments

ok so how can i retrieve this request? can i use $this->input->post('file'); ?
You will use $_FILES['file']['tmp_name'] to get the path to the temporary uploaded file, which you can then copy to your server or do whatever. $_FILES['file']['name'] will include the original path of the uploaded file. There's a lot more detailed information in the docs on PHP.net.
1

You're looking in the wrong superglobal ($_POST). Check $_FILES and make sure that the form's enctype is "multipart/data".

answered Aug 14, 2012 at 13:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.