Welcome Guest, Not a member yet? Register   Sign In
Problem in uploading files(especially image)
#1

[eluser]gmahesha[/eluser]
Hello everyone. i am new to CI.
i have problem in uploading the image. here is my code.

this is in the controller section

class Upload extends Controller {

function Upload()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
}

function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}

function do_upload()
{
$config['file_path'] ='.system/uploads/';
//echo $config['file_path'];

$config['allowed_types'] = 'gif|jpg|jpeg|png|PNG';
$config['max_size'] = '900';
$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);
}
}
}

this is the view part
<?php echo $error;?>

<?php echo form_open_multipart('upload/do_upload');?>

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

<br /><br />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

After submitting the i8mage, it shows "The upload path does not appear to be valid."

i know, i have to set something in the Routes.php or in index.php (?). i dont know wat to set in these files? and where should i keep the uploads file ??

Anyone plz help me... Thanks in advance
#2

[eluser]gmahesha[/eluser]
Hello friends,

i have solved the problem.
in the controller section i have done some changes like

$config['file_path'] =BASEPATH.'uploads/';
$config['upload_path'] = BASEPATH.'uploads/';

because in the upload library, some problem with upload_path value. so in the controller section, i have passed the upload_path ($config['upload_path'] = BASEPATH.'uploads/';
), which is not in the user guide of File upload.

and the image is stored in the folder system/uploads folder.

i am open to any sudgestions.
#3

[eluser]Imran Tariq[/eluser]
Just a hint. You should store the images in a different folder rather than storing them in system directory. It will help you a lot in managing site resources.
#4

[eluser]gmahesha[/eluser]
thanks Imran for ur kind info.




Theme © iAndrew 2016 - Forum software by © MyBB