DotDragnet
May 23, 2012, 02:11:49 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: PHP Check if file exists  (Read 1339 times)
Jeep Stone
Hero Member
*****
Posts: 908



View Profile WWW Awards
« on: June 25, 2007, 01:21:28 PM »

I want to check if an image file exists on the server. I've got an absolute URL so can't use file_exists because of  security restrictions. What's the best way around this?
Logged

Tanthalas
Hero Member
*****
Posts: 1019



View Profile WWW Awards
« Reply #1 on: June 25, 2007, 01:44:29 PM »

Code:
if (! @fopen($filename, "r")) {

  echo("You're having a laugh");

}

?
Logged

Aperture Science
We do what we must because we can
For the good of all of us, except the ones who are dead.
But there's no sense crying over every mistake
You just keep on trying 'til you run out of cake
And the science gets done, and you make a neat gun
For the people who are still alive
JasonD
Global Moderator
Hero Member
*****
Posts: 546



View Profile Awards
« Reply #2 on: June 25, 2007, 01:51:28 PM »

Huh? If you've got an absolute URL you can't use it because the http stream doesn't support stat(), not because of any security restrictions.

$parts = parse_url($your_absolute_url);
file_exists($_SERVER['DOCUMENT_ROOT'] . $parts['path'])

Assuming that is "the server" means the server, and not another server.
Logged
Jeep Stone
Hero Member
*****
Posts: 908



View Profile WWW Awards
« Reply #3 on: June 25, 2007, 02:15:14 PM »

Cheers Jason.
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!