[eluser]tuckee[/eluser]
Hello everyone, I'm really new in uploading image so really appreciate if anyone could help me with this. I have been trying whole day but is still not working. I have a registration form, that has image uploading as well. I have put the image uploading in the same form along with registration information.
When click submit, it successful register, manage to capture ads_name, but it says no image is selected. I believe there is a mistake i made in the view file. maybe the button?
I'm not sure if this is the cause of not detecting any image selected.
Code:
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
If i were to changed to
Code:
( ! $this->upload->register())
I got this error.
Fatal error: Call to undefined method CI_Upload::register() in C:\xampp\htdocs\SS\system\application\controllers\advertisement.php on line 61
ps: I have deleted alot of my code to make this simple.
my controller
Code:
function register(){
$this->form_validation->set_rules('ads_name','Name','trim|required|min_length[2]|max_length[30]|callback_check_ads_name|xss_clean');
if ($this->form_validation->run() == FALSE)
{
//hasn't been run or they are validation errors
$this->load->view('advertisement_view',$this->view_data);
}
else
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$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);
}
else
{
$data = array('upload_data' => $this->upload->data());
$img_url = $data['upload_data']['full_path'];
}
extract($_POST);
echo 'Congratulation' . $ads_name;
echo $image_url;
}
}
my view
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php
echo form_open('advertisement/register');
$ads_name = array(
'name' => 'ads_name',
'id' => 'ads_name',
'value' => set_value('ads_name')
);
?>
<ul>
<li>
<label>Name</label>
<div>
<?php echo form_input($ads_name); ?>
</div>
</li>
<li>
<label>Thumbnail Image</label>
<div>
<?php echo $error;?>
<?php echo form_open_multipart('advertisement/register');?>
<input type="file" name="userfile" size="20" />
</div>
</li>
<li>
<div>
<?php echo form_submit(array('name' => 'register','value' => 'upload'), 'Submit'); ?>
</div>
</li>
</ul>
</form>
</body>
</html>