View Full Version : If file exisits display it, if it doesn't then don't
I know how to do this on the same server, how how do you open it from another server?
I have tried fopen(), file_exists() and file(). None of them seam to have worked.
They all still opened the file even if it didn't exisit.
The reason I need it to not open it is because I need it to enter the ones which do exist into a database.
Protege
15-05-2008, 02:59 PM
http://uk.php.net/function.file-get-contents
IntaMedia
15-05-2008, 06:04 PM
<?php
(@file_get_contents("http://URL_TO_FILE.URL/TO/FILE.TXT"))
{
// Put the stuff you want to show if the file was found here
}
else
{
//Put the stuff you want to show if the file was not found here!
}
?>
:) Hope it helps
Robbie
15-05-2008, 06:07 PM
<?php
$page = $_GET["page"];
if(file_exists($page)) {
include("$page");
} else {
echo("Page doesn't exist");
}
?>
Dentafrice
16-05-2008, 08:00 PM
Just thought I would expand on Robbie!'s:
<?php
$file = "test.php"; // you can enter a path here aswell ex: /home/test/public_html/test.php
if(!file_exists($file)) {
exit("404. File not found!"); // if the file isn't found, display this error.
} else {
include($file); // display the file.
}
?>
Hypertext
16-05-2008, 09:46 PM
Expanding? You've added a comment, and got rid of a $_GET[]...contracting more like it.
None of these work for remote files. Thanks for the help though :)
Robbie
16-05-2008, 09:53 PM
<?php
if(file_get_contents("http://google.co.uk")) {
echo("The page exists!");
} else {
echo("The page does not exist!");
}
?>
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.