[eluser]ray73864[/eluser]
I am using CI 1.6.3 (no modifications) and each time i try to upload an image file the error being returned is: You did not select a file to upload.
I haved checked my html code and i indeed have a input file with the name 'userfile' and when i spit out the value of that field in the upload function it comes back with the filename (eg. blah.jpg) but with no pathnames or anything. I used the example in the user_guide.
The code in my controller:
Code:
function _image_upload($product_id)
{
$config['upload_path'] = '/files/images';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '500';
$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());
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->db->where('id',$product_id);
$this->db->update('product',array('image'=>$data['full_path']));
}
return $error;
}
The controller function for updating my database:
Code:
function update_master_product($productid, $action = "update")
{
if ($action == "update") {
$data = array(
'name'=>$this->input->post('product_name'),
'product_code'=>$this->input->post('product_code'),
'cat_id'=>$this->input->post('category'),
'description'=>$this->input->post('rte')
);
$this->db->where('id',$productid);
$this->db->update('product',$data);
$errors = $this->_image_upload($productid);
if ($this->db->affected_rows() > 0) {
$this->message['type'] = "success";
$this->message['text'] = 'Product updated successfully.';
} else {
$this->message['type'] = 'info';
$this->message['text'] = 'Product not updated.';
print_r($errors);
}
} else if ($action == "delete") {
$this->db->where('id',$productid);
$this->db->delete('product');
if ($this->db->affected_rows() > 0) {
$this->message['type'] = "success";
$this->message['text'] = 'Product deleted successfully.';
} else {
$this->message['type'] = 'error';
$this->message['text'] = 'Product could not be deleted.';
}
} else {
$this->message['type'] = 'error';
$this->message['text'] = 'Invalid action performed on article while updating.';
}
$this->session->set_flashdata($this->message['type'], $this->message['text']);
redirect('/admin_catalogue/products/', 'refresh');
}
And the view itself:
Code:
<?php
include_once "fckeditor/fckeditor.php";
?>
<!-- The main contents of the site -->
<div id="content">
<h3>Product: <?=$product['name'] . " (" . $product['code'] . ")";?></h3>
<?=$this->session->flashdata('message');?>
<p>
<?=form_open_multipart('admin_catalogue/update_master_product/' . $product['id']);?>
<label for="product_name">Product Name: </label>
<input type="text" name="product_name" id="product_name" size="50" value="<?=$product['name'];?>" />
<br />
<label for="product_code">Product Code: </label>
<input type="text" name="product_code" id="product_code" size="50" maxlength="50" value="<?=$product['code'];?>" />
<br />
<label for="userfile">Product Image: </label>
<input type="file" name="userfile" id="userfile" size="100" accept="image/jpeg,image/gif,image/png" />
<p>
<label style="vertical-align: top" for="category">Category:</label>
<?php if ($category->num_rows() > 0): ?>
<select name="category">
<option value="">None</option>
<?php foreach ($category->result() as $row): ?>
<option value="<?=$row->id;?>"
<?=($product['category_id'] == $row->id) ? " selected=\"selected\"" : "";?>
><?=$row->name;?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
No categories found.
<?php endif; ?>
</p>
<br />
<label for="rte">Product Description: </label>
<p>
<?php
$oFCKeditor = new FCKeditor('rte');
$oFCKeditor->BasePath = '/fckeditor/';
$oFCKeditor->ToolbarSet = 'Normal';
$oFCKeditor->Config['ToolbarCanCollapse'] = false;
$oFCKeditor->Value = $product['description'];
$oFCKeditor->Create();
?>
</p>
<p>
<input type="submit" value="Update Product" />
<input type="reset" />
</p>
</form>
</p>
</div>
View code updated so that it shows 'form_open_multipart'