0

I am trying to upload image to my Codeigniter application hosted on Openshift. My app structure is as follows

App
 -libs
 -...
 -php
   - application
   - public
       - uploads

I want to upload images to this uploads folder. my code

    $config['upload_path']=realpath(dirname(__FILE__)).'public/uploads/';
    $config['allowed_types']="jpg|jpeg|gif|png";
    $this->load->library('upload',$config);
    if(!($this->upload->do_upload())){
        $error=array('error'=>$this->upload->display_errors());
        $this->load->view('profile',$error);

    }
    else{

        $file_data=$this->upload->data();
        $data['img']=base_url().'/public/uploads/'.$file_data['file_name'];
        $this->load->view('success',$data);
    }  

But above gives me The upload path does not appear to be valid. error. I have tried several ways. But the problem is the server do not allow to upload to the location.

Normally I can access the files in the uploads folder. But when I try to write data (store file) it doesn't allow. How can I fix this thing.

Note: I want the solution for the Openshift server but not the localhost

Malintha
  • 4,512
  • 9
  • 48
  • 82

1 Answers1

1

The path is supposed to be $OPENSHIFT_DATA_DIR (which points to ~/app_root/data).

You can also write to /tmp but those files will be treated as ephemeral.

You do not have write permissions anywhere in the file system.

TheSteve0
  • 3,530
  • 1
  • 19
  • 25
  • How to define Openshift variable ? I have tries but it tell that the variable did not defined echo $OPENSHIFT_DATA_DIR; ? – Malintha Oct 15 '13 at 16:40
  • 1
    Look at this example to see how to grab the environment variables in your code. In the example we are grabbing DB parameters but you can also use it to grab the data directory http://stackoverflow.com/questions/17016388/mysql-codeigniter-configuration-on-openshift – TheSteve0 Oct 16 '13 at 06:57