SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to make sure a file exists before requiring it?

    Hello,

    My script contains included scripts. I use require_once(). If the script is not there, I get an error. I'd like to know if there is a way to check if the file exists before requiring it.

    I expect people to question my logic: just so you know, I'm working within a wordpress environment, so I just want to make sure that a wp file change name won't affect my code.


  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,407
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If you want to be able to recover then you use include_once() which throws a warning upon failure whereas require which throws a fatal error and stops.


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
  •