[eluser]Unknown[/eluser]
hi everybody.. i'm newbie in Codeigniter,
i want to ask, i got some problems,
my web page didn't want to display the images i've uploaded there. I think i've listed wrong code to generate image url.
for example, the output of image url should like 'http://localhost/shopping/images/baby-doll.jpg' but the output code seems wrong like this, '/shopping/images/baby-doll.jpg' so the images won't displayed.
i put this code in controller,
Code:
//welcome.php
// blablabla
function product($id){
$product = $this->MProducts->getProduct($id);
if (!count($product)){
redirect('welcome/index','refresh');
}
$data['grouplist'] = $this->MProducts->getProductsByGroup(3,$product['grouping'],$id);
$data['product'] = $product;
$data['title'] = "Claudia's Kids | ". $product['name'];
$data['main'] = 'product';
$data['navlist'] = $this->MCats->getCategoriesNav();
$data['assigned_colors'] = $this->MProducts->getAssignedColors($id);
$data['assigned_sizes'] = $this->MProducts->getAssignedSizes($id);
$data['colors'] = $this->MColors->getActiveColors();
$data['sizes'] = $this->MSizes->getActiveSizes();
$this->load->vars($data);
$this->load->view('template');
}
//blablabla
this code in models folder,
Code:
//mproduct.php
//.....
function addProduct(){
$data = array(
'name' => db_clean($_POST['name']),
'shortdesc' => db_clean($_POST['shortdesc']),
'longdesc' => db_clean($_POST['longdesc'],5000),
'status' => db_clean($_POST['status'],8),
'grouping' => db_clean($_POST['grouping'],16),
'category_id' => id_clean($_POST['category_id']),
'featured' => db_clean($_POST['featured'],3),
'price' => db_clean($_POST['price'],16)
);
if ($_FILES){
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '200';
$config['remove_spaces'] = true;
$config['overwrite'] = false;
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
if (strlen($_FILES['image']['name'])){
if(!$this->upload->do_upload('image')){
$this->upload->display_errors();
exit();
}
$image = $this->upload->data();
if ($image['file_name']){
$data['image'] = base_url()."/images/".$image['file_name'];
}
}
if (strlen($_FILES['thumbnail']['name'])){
if(!$this->upload->do_upload('thumbnail')){
$this->upload->display_errors();
exit();
}
$thumb = $this->upload->data();
if ($thumb['file_name']){
$data['thumbnail'] = base_url()."/images/".$thumb['file_name'];
}
}
}
$this->db->insert('products', $data);
$new_product_id = $this->db->insert_id();
if (count($_POST['colors'])){
foreach ($_POST['colors'] as $value){
$data = array('product_id' => $new_product_id,
'color_id' => $value);
$this->db->insert('products_colors',$data);
}
}
if (count($_POST['sizes'])){
foreach ($_POST['sizes'] as $value){
$data = array('product_id' => $new_product_id,
'size_id' => $value);
$this->db->insert('products_sizes',$data);
}
}
}
//....
this code in views folder
Code:
<div id='pleft'>
<?php
echo "<img src='".$mainf[' border='0' align='left'/>\n";
echo "<h2>".$mainf['name']."</h2>\n";
echo "<p>".$mainf['shortdesc'] . "<br/>\n";
echo anchor('welcome/product/'.$mainf['id'],'see details') . "<br/>\n";
echo anchor('welcome/cart/'.$mainf['id'],'add to cart') . "</p>\n";
?>
<br>br/>
<?php
if ($this->session->flashdata('subscribe_msg')){
echo "<div class='message'>";
echo $this->session->flashdata('subscribe_msg');
echo "</div>";
}
echo form_open("welcome/subscribe");
echo form_fieldset('Subscribe To Our Newsletter');
$data = array('name'=>'name', 'id' => 'name','size'=>'25');
echo "<p><label for='name'>Name</label><br/>";
echo form_input($data) . "</p>";
$data = array('name'=>'email', 'id' => 'email', 'size'=>'25');
echo "<p><label for='email'>Email</label><br/>";
echo form_input($data) . "</p>";
echo form_submit("submit","subscribe");
echo form_fieldset_close();
echo form_close();
?>
</div>
<div id='pright'>
<?php
foreach ($sidef as $key => $list){
echo "<div class='productlisting'><img src='".$list[' border='0' class='thumbnail'/>\n";
echo "<h4>".$list['name']."</h4>\n";
echo anchor('welcome/product/'.$list['id'],'see details') . "<br/>\n";
echo anchor('welcome/cart/'.$list['id'],'add to cart') . "\n</div>";
}
?>
</div>
i pick this code from Wrox Professional Codeigniter, but there is much error.
So, where is wrong?
thanks before.