Paths not being read from variable?

I have just the strangest problem and its driving me nuts.

Given a perfectly valid (and tested) path to a file e.g…

uploads/personal_images/foobar/15/DSC01045.JPG

a number of functions I need to work with dont recognise the path unless typed directly into a functions parameter e.g.


$aPath = uploads/personal_images/foobar/15/DSC01045.JPG

if(file_exists($aPath))
{
    echo "file found";
}


returns false, however


if(file_exists("uploads/personal_images/foobar/15/DSC01045.JPG"))
{
     echo "file found";
}

returns true. Which is nuts, and dosent make any sense! Same goes if I pass the same arguments into unlink() or chmod();

If any experienced coders have a clue whats going on, Id be forever in your debt at this is holding up a project :slight_smile:

strings should be quoted in php. It’s not required, but things don’t always work correctly if you don’t.

Also, you should turn up error reporting to a high level when developing. php will be verbose and warn you about potential mistakes you may be making. Just because php gives you a notice about something doesn’t mean the code is wrong or broken. However, you should understand why you get a specific notice, and be able to decide on your own if it’s ok or not.


//top of scripts
error_reporting(E_ALL);
ini_set('display_errors', 1);

hey crmalibu, I really appreciate your input. No luck however :sick:

I don’t think you’ve given us a good representation of your code then. Because, this obviously works.


$aPath = "uploads/personal_images/foobar/15/DSC01045.JPG";

if(file_exists($aPath)) 
{ 
    echo "file found"; 
}
if(file_exists("uploads/personal_images/foobar/15/DSC01045.JPG")) 
{ 
     echo "file found"; 
}

Well then, maybe I just suck at PHP!:slight_smile: