SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    file_exists issue

    I am creating a class that uses the file_exists function and it will not work unless I give the full path to the file from the C:. The file I am checking if exists is in the same folder as the class checking if it exists. Why is this, I thought I could check the file without giving the folders to it.

    Sorry if I confuse any of you.

    Thanks,
    HighCaliber
    GeneralForum
    - To hell with the rest...

  2. #2
    Non-Member
    Join Date
    Feb 2006
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    easy , the solution is =>

    PHP Code:

    if (file_exists(HOMEPATH '/Yourfile.txt'))
        
    echo 
    "File found in the Homepath";

    else
    echo 
    "File Not Found"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is tehere a method to check if a file exists without giving your homepath b/c i am making a class that I want to be easily moved around w/o changing any source code.
    GeneralForum
    - To hell with the rest...

  4. #4
    SitePoint Evangelist superuser2's Avatar
    Join Date
    Aug 2006
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it's going to be in the same directory:

    PHP Code:
    if(file_exists("test.php"))

    You can use relative paths with file_exists.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This class is for unit conversion (trying to pull in file corresponding to conversion). Here is my php function...
    Code:
    			function parse($type, $value, $input, $output) {
    				$file = trim($type) . ".class.php";
    				if (file_exists($file)) {
    					require_once($file);
    					$className = "convert" . ucwords($type);
    					$CLS = new $className;
    					$value = "PHP is gay";
    				}
    				else {
    					$value = $file;
    				}
    				return $value;
    			}
    I am calling the function like so...
    Code:
    parse("alternative", "100", "meters/square second", "feet/square second")
    So basically I am calling the file alternative.class.php and the weird thing is if I change the file_exists() function to the require_once() function the if statement works. I am really lost.
    GeneralForum
    - To hell with the rest...

  6. #6
    SitePoint Enthusiast
    Join Date
    Jan 2006
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nvm figured it out, had to add a few folders due to my index including a class which then included another class

    thanks for all of the help though
    GeneralForum
    - To hell with the rest...

  7. #7
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When you include/require a script in PHP it runs as though it were directly part of the calling code. Meaning once included it only matters where the calling code is, not the class source file.

    Paths will be relative to the calling code.


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
  •