CodeIgniter Forums
Need help getting application base path - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Need help getting application base path (/showthread.php?tid=7714)



Need help getting application base path - El Forum - 04-20-2008

[eluser]mmatos[/eluser]
Hello,

I'm working on my 2nd CI application, and my goal is to make my applications "ultraportable" - basically upload and run.

Right now, I'm working on an image upload/delete administration section.

When a user deletes an image, a function called deleteImage in my model will get called:

Code:
function deleteImage($image_id) {
        $this->db->where('image_id', $image_id);
        $query = $this->getImageById($image_id);        //retrieve some info so we can delete the file.
        $imageinfo = $query->result();
        $imagetodelete = $imageinfo[0]->image_filename;
        $imagepath = $this->config->item('image_uploads');

        $filedelete = $imagepath . $imagetodelete;

        echo "Delete: $filedelete<br><br>";

        print_r($this);
        die();

        $this->db->where('image_id', $image_id);
        $this->db->delete($this->_table);
        return $this->db->affected_rows();
    }

My problem is in this:
Code:
$filedelete = $imagepath . $imagetodelete;

I need to get the FULL path to that image starting from root. I don't see a function in the CI documentation that returns the applications base directory (eg: c:\wamp\www on my dev box, or /home/user/www on prod box.)

For portability reasons, I do not want to hard code it. I'm sure I'm just missing something.

Thanks.


Need help getting application base path - El Forum - 04-20-2008

[eluser]louis w[/eluser]
CI has a var built in, $base_url


Need help getting application base path - El Forum - 04-20-2008

[eluser]mmatos[/eluser]
Thanks, but I am looking for the local file system path, not the URL to the application.


Need help getting application base path - El Forum - 04-20-2008

[eluser]mmatos[/eluser]
It looks like there's been a debate in the past over the exclusion of this.

I found these two related threads, exactly what I needed:

http://ellislab.com/forums/viewthread/45782/
http://ellislab.com/forums/viewthread/47572/


Need help getting application base path - El Forum - 04-20-2008

[eluser]louis w[/eluser]
By local file system path, do you mean the path to the current file? Try $_SERVER["SCRIPT_FILENAME"]


Need help getting application base path - El Forum - 04-23-2008

[eluser]Yunus Khan[/eluser]
You can create easily documentation path / base path easily..

Code:
/*
*create base path
*/
$config['base_path'] = $_SERVER['DOCUMENT_ROOT'] . '/requiredfoldername';
/*



Need help getting application base path - El Forum - 08-08-2008

[eluser]dr.fux[/eluser]
Hello everybody

I just came over the same problem, an i realized, that it wasn't really one for me.

Correct me if I'm wrong, but for me it works just consider the base_path is just the working directory of the running CI script, beacause the index.php file is stored in that directory.

So why not consider
Code:
$base_path = "."
?

This would have the conclusion, that a subdirectory of the base_path could be accessed by something like that:

Code:
$images_dir = "images/"; //means http://www.urdomain.com/any_directory/images/


Are there any cases where the working directory of a CI application would change during system execution?

greets,
sniffer