My HTML:
<?php echo form_open_multipart(base_url() . 'user/' . $this->session->userdata['username'] . '/settings/picture'); ?>
<input type="file" name="photo_data" id="photo_data" value="" />
<input type="submit" value="Save" name="submit" class="button_ui fr" />
<?php form_close(); ?>
So the user goes to its settings page and clicks Picture Tab in the menu which then shows the above HTML and allows the user to update the picture.
I then went into my user controller and tried to check if the user is in the picture tab and print out the data being sent so i can continue coding the rest part… but the thing is that it doesnt print the picture that i select to upload…
My controller code:
if ($this->uri->segment(4) == 'picture'){
if (isset($_POST["submit"])){
print_r($_POST);
}
}
Output:
Array ( [submit] => Save Changes )
As The Maniac pointed out, file uploads are stored in the $_FILES global, not $_POST. But you don’t even need to use these with CodeIgniter (so long as it’s one file upload you’re doing). In your controller, you can use CI’s build-in file upload class:
If you’re uploading multiple files, you’ll need to do a
foreachloop with $_FILES. Find out more about it in their documentation. Also, you can minimize your code in your view with something like: