[eluser]mad82[/eluser]
Code:
hi im new to codeIgniter n have a problem while using the file upload script from user
guide, upload form view is executing and displays the output, but after selecting a
file and click on upload its being directed to XAMP home page as im using XAMP, [quote]Any
help is greatly appreciated.[/quote]
/*this is view code I used upload_form.php code*/
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="file" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
/*this is the controller class I used upload.php code*/
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Upload extends CI_Controller
{
function _construct()
{
parent::_construct();
$this->load->helper(array('form','url','file'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
function do_upload()
{
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT']."uploads";
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size']= '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);/* load library file with specified
configuration*/
$field_name = "file"; /*variable passed to form*/
if (!$this->upload->do_upload($field_name))
{
$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);
}
}
}
?>