• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codeigniter upload path invalid on webserver but valid on local host

I’m hoping someone can help me here as I’m pretty desperate now. Having tested my website on my localhost with no issues whatsoever, I have a photo upload function which doesn’t work now the site is on a remote web-server and judging by the searches I have done, this appears to be fairly common but I am very stuck. When someone tries to upload a photo, the error ‘The upload path does not appear to be valid’ is returned and I can’t figure out why. My suspicion is that the ‘MKDIR’ path isn’t correct relative to where the codeigniter upload function is trying to place the file. But I don’t understand why these scripts worked fine on my local host.
The structure of my site is as follows and I am trying to create subfolders in the main folder ‘PHOTOS’ to upload to:-


Part of my model file (functions used to generate a random string to set the file path and the subdirectory structure):-
class Image_file extends CI_Model {

//generate random string for filename and path
public function string_generate() {

  $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
  $size = strlen($chars);
  $string = '';  
  for ($i = 0; $i < 15; $i++) {  
  $string .= $chars[rand(0, $size - 1)];  
  return $string;


//set image path (generate random code which will also form filename)
public function set_image_path($string) {

  $pos = 6;
  $f = substr($string, 0, $pos);
  $first = chunk_split($f,2,"/");
  $photo_path = 'photos/'.$first;

  return $photo_path;


And this relates to the controller (relevant part shown only):-

//upload photo file
public function upload_file() {
  $mem_id = $this->session->userdata('mem_id');
  $string = $this->image_file->string_generate();
  $set_image_path = $this->image_file->set_image_path($string);
  //check if image exists in directory with same string (unlikely but better safe than sorry!)
  if (file_exists($set_image_path.$string.'.jpeg')) {$string .= substr($this->session->userdata('username'), 0, 4);}
  //echo '<br /><br /><br /><br /><br /><br /><br /><br />'.$set_image_path; exit();
  $config['upload_path'] = $set_image_path;
  $config['allowed_types'] = 'gif|jpg|jpeg|png';
  $config['max_size'] = '4000';
  $config['max_width'] = '6000';
  $config['max_height'] = '4000';
  $config['file_name'] = $string.'.jpeg';  
  $this->load->library('upload', $config);

  //create the directory
  mkdir($set_image_path, 0644, true);

  //do upload & process image (rezize and rename)
  $results = $this->upload->data();
  $error = $this->upload->display_errors('', '');
  if (($error) or (!$this->image_file->check_file_exists($set_image_path.$string.'.jpeg'))) {
   $this->session->set_flashdata('error', $error);
  //write the data to the photo db
  $this->image_file->write_imagedata($mem_id, $string, $set_image_path);
  //load image library

Can anyone help??? I've been trawling through pages and pages of people having a similar issue, but can't seem to solve this one.


Messages In This Thread
Codeigniter upload path invalid on webserver but valid on local host - by El Forum - 09-23-2012, 12:21 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.