I've got the following php in codeigniter:
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '4000';
$config['max_width'] = '3000';
$config['max_height'] = '3000';
$this->load->library('upload', $config);
$image_data = $this->upload->do_upload();
However, when the file is uploaded, $image_data['file_path'] returns as /home/public_html/sitename/uploads. I need it to go to www.domain.com/uploads. Any thoughts on why this may be happening?
I'd prefer to not have to hardcode a str replace in there. Hope this isn't a duplicate.
The data that is returned by the upload function is as per the DOCUMENT ROOT of the application. You can get the file_name and accordingly use the base_url() to get this done
Example.
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '4000';
$config['max_width'] = '3000';
$config['max_height'] = '3000';
$this->load->library('upload', $config);
$image_data = $this->upload->do_upload();
$image_data_file = $image_data["file_name"];
$image_file_url = base_url()."/uploads/".$image_data_file;
Hope this helps.
in the codeigniter docs it is specified that $image['file_path'] returns the absolute server path to the file.
Alternatively you can do
$upload_path = 'uploads/';
$config['upload_path'] = './'. $upload_path;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '4000';
$config['max_width'] = '3000';
$config['max_height'] = '3000';
$this->load->library('upload', $config);
$image_data = $this->upload->do_upload();
$dir_url = base_url($upload_path);
have in mind that you will have to include url helper in codeigniter to use base_url function