Page 1 of 1

Paths like './assets/images/test.jpg' failing on local

Posted: Wed Sep 16, 2009 1:50 pm
by mattpointblank
Hi there all.

I'm integrating phpThumb (a thumbnailing script) with CodeIgniter framework. Both scripts are quite fussy about paths/URLs (in the sense that they're not structured 'physically' through CI, but re-routed).

Anyway, I've been doing some development on my work machine using functions like:

Code: Select all

 
if(file_exists('./assets/images/test.jpg')) { echo 'exists'; } else { echo 'not found'; }
 
This works at my work machine, which has the same folder structure (and yes, the file does exist!)

If I replace the path with the absolute one (eg '../../../assets' etc) it works, but this isn't practical and given CodeIgniter's dynamic URLs, I can't always predict how many levels deep the ../s need to be.

Can anyone think of some php configuration issue that could be causing this? It's driving me mad trying to get these root paths working!

Matt

Re: Paths like './assets/images/test.jpg' failing on local

Posted: Wed Sep 16, 2009 3:38 pm
by requinix
Paths like "./assets/images/test.jpg" are relative to the current working directory. That's not always the same as the directory the current script is in.
mattpointblank wrote:If I replace the path with the absolute one (eg '../../../assets' etc) it works
That's not absolute - it's still relative.

An absolute path looks like

Code: Select all

$_SERVER["DOCUMENT_ROOT"] . "/assets/images/test.jpg"
dirname(__FILE__) . "/assets/images/test.jpg"
The former is when you know that /assets is in the document root, the latter is when /assets is in the same directory as the script.

Re: Paths like './assets/images/test.jpg' failing on local

Posted: Thu Sep 17, 2009 2:52 am
by mattpointblank
Ah, thank you. I tried echoing out getcwd() and it was the same root directory that my assets folder is in, but because of CodeIgniter's structure, the URL to my page is something like mysite.com/articles/view/123, which complicates paths and links. I'll try using one of the above methods and see if that makes a difference.