CodeIgniter upload class does is not returning the right full_path. I am trying to upload an image. I write up this code
$config['encrypt_name'] = TRUE;
echo $config['upload_path'] = FCPATH .'contest/videos/';
$config['max_size'] = '1000000000000000';
$config['allowed_types'] = '*';
$config['file_name'] = $_FILES['userfile']['name'];
$this->load->library('upload', $config);
$this->upload->initialize($config);
But it keeps asking that the permission denied. When I check the $this->upload->data() I see the full_path does not have last trailing slash after the last folder. See the print_r result
Array
(
[file_name] => testvdo.mp4
[file_type] =>
[file_path] => /var/www/html/zebra_1975/contest/videos
[full_path] => /var/www/html/zebra_1975/contest/videostestvdo.mp4
[raw_name] => testvdo.mp4
[orig_name] =>
[client_name] =>
[file_ext] =>
[file_size] =>
[is_image] =>
[image_width] =>
[image_height] =>
[image_type] =>
[image_size_str] =>
)
There should be a slash after video in full_path. What I am doing wrong here?
Try this I hope it will help you to set yours properly.
if (isset($_FILES['profile_img']) && !empty($_FILES['profile_img']['name']))
{
$user_img_path = './public/uploads/images/users/';
$config['upload_path'] = $user_img_path;
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$config['encrypt_name'] = TRUE;
$config['file_name'] = $img_name;
$config['max_size'] = '9999';
$config['max_width'] = '1524';
$config['max_height'] = '868';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('profile_img')){
$error = array('error' => $this->upload->display_errors());
print_r($error);
}
else{
$image = $this->upload->data();
print_r($image);
}
}
I am using this in my project
So for me I used this and is working for me
$user_img_path = './public/uploads/images/users/';
OR
$user_img_path = FCPATH'./public/uploads/images/users/';
OR
Editing Yours
$config['upload_path'] = FCPATH .'/contest/videos/';
Instead of
$user_img_path = FCPATH .'contest/videos/';
So try it. If it work for you let me know I am here to help
Related
I would like to rename a file when I upload this file.
So the content of the add_land_short should get the name of the file.
So if the input test is, the file test.png is.
Controllers:
public function insert_land()
{
$land_short = $this->input->post('add_land_short');
$config['upload_path'] = './assets/images/site/flag/';
$config['allowed_types'] = '*';
$config['max_size'] = '2048';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
$errors = array('error' => $this->upload->display_errors());
$post_image = 'noimage.jpg';
}
else
{
$data = array('upload_data' => $this->upload->data());
$post_image = $_FILES['userfile']['name'];
}
$this->Admin_model->insert_land();
redirect('admin/land/');
}
Model:
public function insert_land()
{
$this->db->where('tb_land_name', $this->input->post('add_land_name'));
$this->db->where('tb_land_kurzel', $this->input->post('add_land_short'));
$this->db->where('tb_land_img', $this->input->post('add_land_short'));
$result = $this->db->get('db_land');
if($result->num_rows() < 1)
{
$data = array( 'tb_land_name' => $this->input->post('add_land_name'),
'tb_land_kurzel' => $this->input->post('add_land_short'),
'tb_land_last_buy' => date('Y-m-d'),
'tb_land_img' => $this->input->post('add_land_short'),
);
return $this->db->insert('db_land', $data);
}
}
Try This
$file_name = time() . rand(0, 9999) . "." . pathinfo($_FILES['userfile']['name'], PATHINFO_EXTENSION);
$land_short = $this->input->post('add_land_short');
$config['upload_path'] = FCPATH . 'assets/images/site/flag/';
$config['allowed_types'] = '*';
$config['max_size'] = '2048';
$config['max_width'] = '2000';
$config['max_height'] = '2000';
$config['file_name'] = $file_name;
$this->load->library('upload', $config);
if (!$this->upload->do_upload()) {
$errors = array('error' => $this->upload->display_errors());
$post_image = 'noimage.jpg';
redirect('admin/land/');
} else {
$data = array('upload_data' => $this->upload->data());
$post_image = $file_name;
}
In codeigniter while I uploading the image and store image name in database If actual image name is like "abc data.jpg" and I want to store image name like abc_data.jpg and also with this name image should move in uploads folder.
This is my image Upload Code:-
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 5000;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ($this->upload->do_upload('cover_image'))
{
$data =$this->upload->data();
$data_ary = array(
'project_id' => (int)$iProjectId,
'image_url' => $data['file_name'],
'is_covred_photo' => 'YES'
);
$this->db_project->insert( $this->sTable6 , $data_ary);
$aResp = array( 'project_images_id' => $this->db->insert_id());
}
Add $config['file_name']
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = 5000;
$config['file_name'] = 'My_new_file_name'; # Add here
$this->load->library('upload', $config);
remove this line as well
$this->upload->initialize($config);
Try this:
$file_name = $_FILES['file_view_name']['name'];
$file_name_pieces = split('_', $file_name);
$new_file_name = '';
$count = 1;
foreach($file_name_pieces as $piece)
{
if ($count !== 1)
{
$piece = ucfirst($piece);
}
$new_file_name .= $piece;
$count++;
}
$config['file_name'] = $new_file_name;
Refer this
i want to upload an ods file ,but its showing an error:
The filetype you are attempting to upload is not allowed
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'ods|csv|xls';
// $config['max_size'] = '';
$config['max_width'] = '';
$config['max_height'] = '';
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('uploadstatement',$error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$data1=$this->upload->data();
$csv_file1=$data1['file_name'];
added/replaced the following line to the mime types file application/config/mimes.php
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
How can i delete image files from uploaded folder in codeigniter from delete button??
Can any one guide me ???
Here is my controller that upload image files
private function upload() {
$config['upload_path'] = 'assets/uploads/orginal/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|x-png';
$config['max_size'] = '500';
$config['max_width'] = '1600';
$config['max_height'] = '1200';
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if ($this->upload->do_upload()) {
$img = $this->upload->data();
// create thumbnail
$new_image = 'assets/uploads/thumbs/' . $img['file_name'];
$c_img_lib = array(
'image_library' => 'gd2',
'source_image' => $img['full_path'],
'maintain_ratio' => TRUE,
'width' => 100,
'height' => 100,
'new_image' => $new_image
);
$this->load->library('image_lib', $c_img_lib);
$this->image_lib->resize();
} else {
$this->data['error'] = $this->upload->display_errors();
}
}
Use the unlink() function:
unlink($new_image);
http://pt1.php.net/manual/en/function.unlink.php
How to edit this data with image inside.Data have been updated when i press the button "submit", but the old image can not change with the new image
if($this->input->post('go_upload'))
{
validation.......
$IdPerumahan = $this->uri->segment(3);
if ($this->form_validation->run() == TRUE)
{
$lokasi_file = $_FILES['userfile']['tmp_name'];
$nama_file = $_FILES['userfile']['name'];
$ukuran_file = $_FILES['userfile']['size'];
$direktori_file = "./images/$nama_file";
if (empty($lokasi_file))
{
$this->load->model('PerumahanMDL');
$this->PerumahanMDL->SimpanUbahPerumahan($IdPerumahan);
redirect('PerumahanCON');
} else
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg|png';
$config['max_size'] = '2000';
$config['overwrite'] = 'true';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$field_name = "userfile";
if(!$this->upload->do_upload("userfile"))
{
$data['data']= 'TambahPerumahanVW';
$this->load->view('Desain2',$data);
}else
{
$asdf = $this->upload->data();
$config = array(
'source_image' => $asdf['full_path'],
'new_image' => './images/thumb',
'maintain_ration' => true,
'width' => 180,
'height' => 120
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$userfile = $_FILES['userfile']['name'];
$this->load->model('PerumahanMDL');
$this->PerumahanMDL->UbahDataPerumahan($userfile,$IdPerumahan);
redirect('PerumahanCON');
}
}
}
}
}
Add overwrite = true.
$this->load->library('upload', $config);
$this->upload->overwrite = true;