CodeIgniter does not pass from mail data

I am trying to upload a file to CodeIgniter, but when I add enctype = "multipart form-data", no data to write will pass. Not even in other areas. However, when I do not add it, I can get other data, but, of course, not upload files. What is wrong here. Here is my view and controller:

View:

<h2>Add a New Album</h2> <form enctype="multipart/form-data" method="post" action="<?php echo base_url();?>index.php/photo/newAlbum"> <table style="margin-left:5px;"> <tr> <td> Album Name:</td> <td><input type="text" name="name" /></td> </tr> <tr> <td> Photo .zip File:</td> <td><input type="file" name="userfile" size="20" /></td> </tr> <tr> <td></td> <td><input type="submit" value="Upload Photo File" /></td> </tr> </table> </form> 
Controller

contains only

 var_dump($_POST); 

Result:

 array(0) { } 
+8
php upload forms codeigniter
source share
8 answers

You can add this form attribute:
enctype="multipart/form-data;charset=utf-8"
Instead:
enctype="multipart/form-data"
You can see the link.

+3
source share

In fact, multipart data like image / zip or some other blob data will be included in the $ _FILES array, not the $ _POST array.
I recommend you use the download library.

view: upload_form.php

 <html> <head> <title>Upload Form</title> </head> <body> <?php echo $error;?> <?php echo form_open_multipart('upload/do_upload');?> <input type="file" name="userfile" size="20" /> <br /><br /> <input type="submit" value="upload" /> </form> </body> </html> 

view: upload_success.php

 <html> <head> <title>Upload Form</title> </head> <body> <h3>Your file was successfully uploaded!</h3> <ul> <?php foreach($upload_data as $item => $value):?> <li><?php echo $item;?>: <?php echo $value;?></li> <?php endforeach; ?> </ul> <p><?php echo anchor('upload', 'Upload Another File!'); ?></p> </body> </html> 

controller: upload.php

 <?php class Upload extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper(array('form', 'url')); } function index() { $this->load->view('upload_form', array('error' => ' ' )); } function do_upload() { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; $config['max_width'] = '1024'; $config['max_height'] = '768'; $this->load->library('upload', $config); if ( ! $this->upload->do_upload()) { $error = array('error' => $this->upload->display_errors()); $this->load->view('upload_form', $error); } else { $data = array('upload_data' => $this->upload->data()); $this->load->view('upload_success', $data); } } } ?> 

And that's all

+2
source share

You need to fix your do_upload , like this ..

 $this->upload->do_upload('name-of-input-file-element-of-your-form') 

For example, in your view code, you have:

 <input type="file" name="userfile" size="20" /> 

So your do_upload line should look something like this:

 $this->upload->do_upload('userfile') 

Saludos!

+2
source share

Interesting. The code you posted should work. I did a quick test script using your form, and both $ _FILES and $ _POST files went through a fine.

I found this previous question about SO: PHP - parsing multiple form data

This seems to be the same problem as yours. Unfortunately, there was no real answer to this problem. I would think that it could be a server configuration problem - can you try the same code on another server and see if it works?

The only other bit of information I can find was in the answer to this question, $ _ POST data is returned empty when headers> Post_max_size

If you are trying to load a file that is too large, apparently this could cause PHP to throw out the $ _POST data. But if you tried submitting your form without uploading the file (but still using "multipart / form-data") and still you don’t see any $ _POST data that doesn’t apply.

+1
source share

Check for the possibility of improper redirection in the CI layer. This can be caused by an incorrect URL request (for example, a slash // missing at the end of the URL). Redirects delete any POST data (I dealt with this).

So, make sure you use the full URLs in the form action.

Check also .htaccess and $config['uri_protocol'] .

+1
source share

I had the same problem. I decided it like that. in the application /config/config.php you set base_url remember that this URL must be exactly the same as the one you invoke your web application. For me, I called the domain from www.sdfsd.com, but in the configuration file I wrote http://sdfsd.com , so the form POST did not work. So I changed it and now everything works!

amuses

+1
source share

I also had this problem. I do not agree with the above answers. I think the most important thing is at what stage of your controller are you trying to get data for publication. Perhaps you could host the appropriate part of your controller. I found that both mail data and download data become available only after a call

 this->upload->do_upload() 

Obviously, you are using the if statement to verify success. In case of success

 $this->upload->data() 

returns a standard array with information about the downloaded file and

 $this->input->post('name_of_your_form_element') 

Filled with what you entered in the corresponding form element.

0
source share

I had a similar problem. Turns off POST data empty when you exceed the maximum download size / maximum message size. This answer fixed my problem and allowed me to see the $ _POST and $ _FORM data: $ _ POST data is returned empty when the headers> Post_max_size

0
source share

All Articles