0

i am a beginner at codeigniter. since past 2 days i've been trying to build a file upload system using CI's guide. The problem is that the images are not getting uploaded in the upload directory ./uploads/ I suspect that the problem lies with the permissions of the upload folder but i am not sure. I am building the application locally using XAMPP on Windows 7. after pushing the upload button, nothing happens. (it is supposed to either show display errors or redirect to a success page.)

View- upload_form.php `

    <title>Upload Form</title>
</head>

<body>
<form>

<?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>

success page - upload_success.php

<html>

<head>
<title>Upload Form</title>
</head>


<body>

<h3>Your file was uploaded successfully</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|png|jpg|jpeg' ;
    /*$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); //show error page
}

else
{


    $data = array('upload_data' => $this->upload->data());

    $this->load->view('upload_success' , $data);
}
}

}

?>

routing - routes.php

$route['default_controller'] = 'welcome';
$route['404_override'] = "";

$route['(:any)'] = "upload";
  • [Enable errors reporting and display](http://stackoverflow.com/questions/9587413/codeigniter-displays-a-blank-page-instead-of-error-messages#answer-9589988). – Tpojka Jul 08 '15 at 09:18

1 Answers1

2
 View- upload_form.php    
 <form> //remove these thing, form_open_multipart('upload/do_upload') will do the job. If you are giving both, then one form tag is unable to find it's closing tag and action path;

 In controller, make sure $config['upload_path'] = './uploads/'; path is writable and it exist.

Rest code is looking good and workable.