Codeigniter do_upload () silently fails on "success"

I use CodeIgniter to write image upload form. Earlier I had a similar code to work on another site. Currently, the code for receiving an image with multiple data / data forms does not work. When configuring the server / script, I got errors, such as the wrong file path, inconsistent mime types, but now I get nothing.

The code below returns: "ABC" and crashing before "D" without error.

If I change 'photo_filedata' to 'photo_filedata2', I get a more useful error: "ABCD You did not select a file to upload."

I have a complete loss to debug this, since I do not receive errors from the server at all.

Does anyone know what could happen?

Server: WAMP, running on Windows 7. Has an existing project that downloads files without problems.

function upload_photo() { echo "A"; $config['upload_path'] = './images/uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['file_name'] = 'photo_' . substr(md5(time()), 0, 16); $config['max_size'] = 2000; $config['max_width'] = 0; $config['max_height'] = 0; echo "B"; $this->load->library('upload', $config); echo "C"; $result = $this->upload->do_upload('photo_filedata'); echo "D"; if (!$result) { $error = $this->upload->display_errors(); $data = false; } else { $error = false; $data = $this->upload->data(); } $this->load->view('home-photo-upload', array('error' => $error, 'data' => $data)); } 
+6
source share
3 answers
 $config['upload_path'] = 'uploads/category/'.$id.'/'; //echo $file_name;die; //echo $config['upload_path']; $config['allowed_types'] = 'gif|jpg|jpeg|png'; $config['max_size'] = '750'; $config['max_width'] = '1920'; $config['max_height'] = '1280'; $this->load->library('upload'); foreach ($_FILES as $key => $value) { //print_r($key); if (!empty($key['name'])) { $this->upload->initialize($config); if (!$this->upload->do_upload($key)) { // echo 'test';die; // rmdir('uploads/category/'.$id); $errors = $this->upload->display_errors(); flashMsg($errors); } } } 

try it!

+1
source

Your output of maxwidth and maxheight at zero can be a problem if you check this.

0
source

(Cancel from comments): There was a typo / error in the file system / application / config / mimes.php, due to which the is_allowed_filetype () method ended with an error in do_upload ();

 Erronous: ... 'gif' => array('image/gif', 'application/octet-stream'), 'jpeg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'), 'jpg' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'), 'jpe' => array('image/jpeg', 'image/pjpeg', 'application/octet-stream'), 'png' => array('image/png', 'image/x-png', 'application/octet-stream' ); 

// absent) for the final record. - John Beech (aka Markivyan)

Any errors in the CodeIgniter configuration files seem to fail, so no further errors are reported. The problem was found by debugging the internal CI method to find out which line failed.

0
source

Source: https://habr.com/ru/post/891073/


All Articles