Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    file_exists() path problem

    Hello

    I am using the file_exists() function, but since I use a wrong path, it is not working as supposed.

    Here the code:
    Code:
    define ('IMGDIR', '/components/com_virtuemart/shop_image/product/');
    
    file_exists(IMGDIR);
    The pictures are located here (as example only my-site.org):
    Code:
    http://www.my-site.org/components/com_virtuemart/shop_image/product/05.jpg
    path found in cpanel:
    /public_html/components/com_virtuemart/shop_image/product

    What path do I have to use for file_exists() that it is working?
    Last edited by schmek; 05-31-2011 at 12:08 PM.

  • #2
    Regular Coder
    Join Date
    May 2010
    Location
    Bathurst, Australia
    Posts
    180
    Thanks
    1
    Thanked 22 Times in 22 Posts
    Is that all of your code? file_exists() returns a bool. It's intended to be used in conditions eg
    Code:
     
    if(file_exists(IMGDIR)){
       // do some stuff
    }
    Also note i've never played with define, it may do some things i'm don't know of. Above code will work if it was just assigned as a normal variable.
    Disclaimer: I'm hungover 70% of the time i'm on here, any information given may not be correct, or even legible.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,322
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by schmek View Post
    path found in cpanel:
    /public_html/components/com_virtuemart/shop_image/product

    What path do I have to use for file_exists() that it is working?
    The same path as cpanel gives. You can't use a url with file_exists() as it is for detecting a file on the local file system or a network share file system.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    You can't use the same root folder in the PHP script that you would use in the HTML document because they don't use the same root.

    Your path you are using points to the web root when accessed from the web (as a link would be). But when accessed server-side (as in a PHP script) you are not confined to the web root. You can go to levels of the file tree above the web root (which is what you are doing, only you're not coming back down to the web root to find your files).

    The bottom line is that you need to make that root path factor-in the part of the file tree that is above the web root.

    For example, if you have a PHP page located at http://www.example.com/some_folder/index.php and you were to run this code in your script some place convenient and see what it prints to the page:

    PHP Code:
    print __FILE__
    You might expect to see something like "/some_folder/index.php". But what you would really see is something like "/home/user/public_html/some_folder/index.php"

    In this example it is the "/home/user/public_html" part that you are missing from your root path that you would want to specify in the script.

    So, depending on what your server's file tree is like, your path is probably supposed to be something like "/home/schmek/public_html/components/com_virtuemart/shop_image/product/".
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting


  •  

    Posting Permissions

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