Welcome Guest, Not a member yet? Register   Sign In
Baffled by path construction to images directory

Hi there. First post. New CI user.

Ok, quick hello first. Longtime programmer (ie: punch cards, reel-to-reel, papertape, etc.) finally learning php and web technology. Did some python dev with django. That's why I started looking at other frameworks. Not a big fan of php, until I discovered CodeIgniter. It was love at first site! Incredibly elegant and intuitive. Very impressed.

I don't generally post to forums unless I'm really stumped. I used the uploader easily and with success to move and resize a bunch of images. But no matter how I constructed my path to query their existence or get their size they could not be found. The only time I could see them was when using a local fullpath, which is obviously not very useful outside of my local dev environment.

After some testing I found a couple path constructions that worked, but I'm not sure why. Here are the variations I tried in a test controller, followed by their results:

echo "<h2>base_url(): " . base_url() . "</h2>";
echo "<h2>APPPATH: " . APPPATH . "</h2>";
echo "<h2>realpath(APPPATH): " . realpath(APPPATH) . "</h2>";
echo "<h2>BASEPATH: " . BASEPATH . "</h2>";

// absolute local fullpath
$result = file_exists("C:/wamp/www/ci_proj/images/testpics/mypic.jpg");
echo "<h2>abs local fullpath: $result</h2>";

// relative path
$result = file_exists("../images/testpics/mypic.jpg");
echo "<h2>rel path: $result</h2>";

// APPATH with up-path
$result = file_exists(APPPATH."../images/testpics/mypic.jpg");
echo "<h2>APPPATH with up-path: $result</h2>";

// ci proj name path
$result = file_exists("ci_proj/images/testpics/mypic.jpg");
echo "<h2>proj name path: $result</h2>";

// ci proj name root path
$result = file_exists("/ci_proj/images/testpics/mypic.jpg");
echo "<h2>proj name root path: $result</h2>";

// base_url()
$result = file_exists(base_url() . "images/testpics/mypic.jpg");
echo "<h2>base_url(): $result</h2>";

$result = file_exists(BASEPATH."images/testpics/mypic.jpg");
echo "<h2>BASEPATH: $result</h2>";

// BASEPATH with up-path
$result = file_exists(BASEPATH."../images/testpics/mypic.jpg");
echo "<h2>BASEPATH with up-path: $result</h2>";
-- RESULT (via a view) --
base_url(): http://localhost/ci_proj/
APPPATH: application/
realpath(APPPATH): C:\wamp\www\ci_proj\application
BASEPATH: C:/wamp/www/ci_proj/system/

abs local fullpath: 1
rel path:
APPPATH with up-path: 1
proj name path:
proj name root path:
BASEPATH with up-path: 1
I looked around for answers, but couldn't find any that worked. Hence my little experiment.

Clearly APPPATH.'../images/...' is the only usable construction. However, having to construct a path to include a relative up-path doesn't make sense to me (even if it were a symlink). It's ugly, but it works.

So even though I have a workaround, I'd still be grateful if someone could explain to me why I must use this ugly construction.

(Note: This doesn't seem to have anything to do with $config['index_page'] since it was happening both before and after I was able to mod_rewrite the urls, which is a story in itself. Took a long to find the answer, which turned out to be uncommenting the line
LoadModule rewrite_module modules/mod_rewrite.so
in the httpd.conf file, something you might want to mention in your guide.)

Just for the record, I'm developing using WAMP2.2, NetBeans7.3, CI 2.1.3.

Thank you.

Theme © iAndrew 2016 - Forum software by © MyBB