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?
2 Answers 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.
2 Comments
$_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.You're looking in the wrong superglobal ($_POST). Check $_FILES and make sure that the form's enctype is "multipart/data".