SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot thetzfreak's Avatar
    Join Date
    Aug 2004
    Location
    United States
    Posts
    154
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checking file permissions using PHP

    I'm making a script that searches for files online, much like google images for finding pictures. However, much of the time, even if I find a link to an image, I get a 404 error or a file permission error; I'm "forbidden" to access this file. How can I check using php function if this file is accessible?

    I gathered as a test a list of a few working URLs and a few non-working URLs, and I tried using if (file_exists()) to check if they existed, but all of them seemed not to exist =\ Then, I tried using if (is_readable()) hoping that if there weren't enough permissions to let me access the file (such as a jpg), it would let me know. But, this didn't work either as it showed ALL the files as working normally (even the broken ones).

    How can I escape the files automatically that can't be accessed?

    Thanks.

  2. #2
    SitePoint Addict Trent Reimer's Avatar
    Join Date
    Sep 2005
    Location
    Canada
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "file_exists()" and "is_readable()" are really designed to be used on your own server's filesystem rather than on remote URL's.

    You may be better off reading the headers the remote server is returning when you try to access the file. If it contains an error code you can stop right there. Also, the "Content-type" header should confirm that it is some kind of image.

    http://www.php.net/manual/en/function.get-headers.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
  •