SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Accessing File

  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Accessing File

    Hi guys

    I need to access a file in a folder which cannot be accessed if typed in to the url bar

    When I access the folder I get this message

    You don't have permission to access /cv on this server.
    Which is fine. But when I try to open the file like this

    PHP Code:
    $handle fopen("cv/24CV.doc""r"); 
    But this tells me permission is denied

    How can I get round this?

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2009
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you using this in your coding??

    For fopen=
    Code:
    <?php
    $handle = fopen("/home/rasmus/file.txt", "r");
    $handle = fopen("/home/rasmus/file.gif", "wb");
    $handle = fopen("http://www.example.com/", "r");
    $handle = fopen("ftp://user:password@example.com/somefile.txt", "w");
    ?>
    Now the actual one
    Code:
    <?php
    $filename = "c:\\files\\somepic.gif";
    $handle = fopen($filename, "rb");
    $contents = fread($handle, filesize($filename));
    fclose($handle);
    ?>
    Submit Articles

  3. #3
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    First off, file_get_contents is a lot easier to work with than fopen/fread and should be used unless the file is too big to work with in one go or you are on PHP 4 prior to 4.3.

    Second, you'll probably need to provide the complete path to the file if it is in a directory outside of your web path.

    If the directory is in the web path and apache can't read it then PHP can't read it either under any circumstances. You will have to use chmod to make it readable.

    Finally you may run into trouble with open_base_dir depending on the server settings when accessing files not on the web path.


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
  •