My upload_form.php script <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <!--<form action="" method="post">--> <?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"/> <?php form_close(); ?> </body> Upload.php inside controller <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Upload extends CI_Controller { function __construct() { parent::__construct(); $this->load->helper(['form', 'url']); } public function index() { $this->load->view('upload_form', ['error' => ' ']); } public function do_upload() { $config = [ 'upload_path' => './uploads/', 'allowed_types' => 'gif|jpg|png', 'max_size' => 100, 'max_width' => 1024, //Mainly goes with images only 'max_heigth' => 768, ]; $this->load->library('upload', $config); if (!$this->upload->do_upload('userfile')) { $error = ['error' => $this->upload->display_errors()]; $this->load->view('upload_form', $error); } else { $data = ['upload_data' => $this->upload->data()]; $this->load->view('upload_success', $data); } } } When no file select it gives proper error. But on selecting other file (text or image) no error given. Only display blank page move uploaded file is working. Upload Success <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> |
|