I wonder whether someone may be able to help me please.
I’m trying to retrieve the file path for an xml file that I use to in a image gallery script I’m building.
My folder structure is as follows:
website/development/UploadedFiles/’username’folder/’location’
folder/file.xml
I’ve put together this to try and get me the path:
<?php
chdir('var/www/');
echo realpath('./././file.xml');
?>
But I receive the following error:
Warning: chdir() [function.chdir]: No such file or directory (errno 2)
in /homepages/2/d333603417/htdocs/development/real.php on line 2
I’m sure that I’m making a beginners mistake here, but I wanted to have at least given it a try. I just wondered whether someone could possibly take a lok at this please and let me know where I’m going wrong.
Many thanks
If you want to obtain the absolute path of a file relative to your php file, it is usually easier to do something like
dirname(__FILE__).'/path/to/file'since it’s much more predictable than using chdir with relative paths. You can also just echo it for debugging.So in your case, it looks like you might want to have something like this:
If you need to traverse directories upwards, you do it with multiple dirnames: