Im trying to create an advert template but can not get the photos to upload. I dont receive any errors. Ive simplified the coding so that it focuses only on the uploading of one photo, as follows;
This is the Controller coding;
PHP Code:
public function drinkadvert()
{
$this->load->library('image_lib');
$this->load->helper(array('form','file'));
$this->load->library('upload');
$lcuser = $this->session->userdata('user_name');
$drink = $this->input->post('dri');
$drinkphoto = $this->input->post('drinkphoto');
{
$this->load->view('affairs/drinkadvert');
}
$config['upload_path'] = 'mem/'.$lcuser.'/adverts/'.$drink;
$config['allowed_types'] = 'png|jpg|jpeg';
$this->upload->initialize($config);
if($this->upload->do_upload("$drinkphoto"))
{
$img = $this->upload->data();
$drinkphoto = 'mem/'.$lcuser.'/adverts/'.$drink/$img['file_name']; //The problem may lie in the file_name but I dont know much about that.
}
}
public function upload_drinkphoto($str)
{
$allowed_mime_type_arr = array('image/png','image/jpg','image/jpeg');
if(isset($_FILES['drinkphoto']['name']) && $_FILES['drinkphoto']['name']!="")
{
$mime = get_mime_by_extension($_FILES['drinkphoto']['name']);
if(in_array($mime, $allowed_mime_type_arr))
{
return TRUE;
}
else
{
$this->form_validation->set_message('upload_drinkphoto', 'Upload in png/jpg/jpeg format');
return FALSE;
}
}
}
This is the view coding.
PHP Code:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<body>
<?php echo form_open_multipart('drinkadvert'); ?>
<style type="text/css"> .drinkpic { position: fixed; width: 28%; right: 8%; top: 34%; background-color: White; } </style>
<div class="drinkpic"> <input type="file" name="drinkphoto" id="drinkphoto" style="width: 100%; height: 5mm"; > </div>
<style type="text/css"> .sub { position: fixed; width: 5%; right: 19%; text-align: center; top: 83.5%; } </style>
<div class="sub"> <input type="submit" value="Submit"></form></div>
The remedy to this problem must be simple. Can anybody tell me what it is?