Codeigniter上的上传路径在Openshift中出错

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

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.