Welcome Guest, Not a member yet? Register   Sign In
Help uploading file path to database
#1

[eluser]ICS4U1[/eluser]
Hello, I am trying to upload an image path to a database and cannot figure it out.

Code:
//data model @@@@@@@@@@@@@


function getAll() {
  
  $q = $this->db->get('data');
  
  if($q->num_rows() > 0) {
   foreach ($q->result() as $row) {
    $data[] = $row;
   }
   return $data;
  }  
  
}
function add_record($data)
{
  $this->db->insert('data', $data);
  return;
}

//IMAGE @@@@@@@@@@@@@@@@@@@@@

var $gallery_path;
var $gallery_path_url;

function data_model() {
  
  $this->gallery_path = realpath(APPPATH . '../upload');
  $this->gallery_path_url = 'http://localhost/OscarProject/upload/';
}

function do_upload() {
  
  $config = array(
   'allowed_types' => 'jpg|jpeg|gif|png',
   'upload_path' => $this->gallery_path,
   'max_size' => 2000
  );
  
  $this->load->library('upload', $config);
  $this->upload->do_upload();
  $image_data = $this->upload->data();
  
  $config = array(
   'source_image' => $image_data['full_path'],
   'new_image' => $this->gallery_path . '/thumbs',
   'maintain_ratio' => true,
   'width' => 150,
   'height' => 100
  );
  
  $this->load->library('image_lib', $config);
  $this->image_lib->resize();
  
  
}

function get_images() {
  
  $files = scandir($this->gallery_path);
  $files = array_diff($files, array('.', '..', 'thumbs'));
  
  $temp = array();
  
  foreach ($files as $file) {
   $temp []= array (
    'url' => $this->gallery_path_url . $file,
    'thumb_url' => $this->gallery_path_url . 'thumbs/' . $file
   );
   $images = $temp[0];
  }
  
  return $images;
}



CONTROLLER
Code:
// CONTROLLER

function create()
{
$this->load->model('data_model');
  $data = array(
   'item' => $this->input->post('item'),
   'price' => $this->input->post('price')/*,
   'image' => $this->input->post('image')*/
  );
  if ($this->input->post('temp')) {
   $this->data_model->do_upload();
  }
  
  $data['images'] = $this->data_model->get_images();
  $this->load->model('data_model');
  $this->data_model->add_record($data);
  
  $this->crud();

}

VIEW

Code:
// VIEW

</tr>
    <td> &lt;?php echo $row ->item;?&gt;</td>
    <td> &lt;?php echo $row ->price;?&gt;</td>
    <td>&lt;?php echo anchor("site/delete/$row->id", "Delete"); ?&gt;</td>
    <td>&lt;?php echo anchor("site/update/$row->id", "Update"); ?&gt;</td>
    <td><a><img src="&lt;?php echo base_url().$row-&gt;images;?&gt;"></a></td>
    
    
    
    </tr>
    &lt;?php endforeach ;?&gt;
    
    
    </table>
    &lt;?php endif; ?&gt;

    
   </div>
      <h2>Create</h2>
   &lt;?php echo form_open('site/create');?&gt;
  
   <p>
    <label for="title">Item:</label>
    &lt;input type="text" name="item" id="item" /&gt;
   </p>
  
   <p>
    <label for="content">Price:</label>
    &lt;input type="text" name="price" id="price" /&gt;
   </p>
  
   <p>
    <label for="content">Image:</label>


Messages In This Thread
Help uploading file path to database - by El Forum - 06-06-2012, 09:52 AM
Help uploading file path to database - by El Forum - 06-06-2012, 12:04 PM
Help uploading file path to database - by El Forum - 06-06-2012, 12:07 PM
Help uploading file path to database - by El Forum - 06-06-2012, 12:22 PM
Help uploading file path to database - by El Forum - 06-07-2012, 09:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB