SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.
    PHP Code:
    $aPath uploads/personal_images/foobar/15/DSC01045.JPG

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

    returns false, however

    PHP Code:
    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

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    PHP Code:
    //top of scripts
    error_reporting(E_ALL);
    ini_set('display_errors'1); 

  3. #3
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey crmalibu, I really appreciate your input. No luck however

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you've given us a good representation of your code then. Because, this obviously works.

    PHP Code:
    $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"


  5. #5
    38911 Basic Bytes Free johnuk's Avatar
    Join Date
    Jul 2008
    Location
    Somerset, England
    Posts
    458
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well then, maybe I just suck at PHP!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •