Sorry guys, I have been trying a number of differrent ways to do this but I am now totally confused.
My require is:
1. Check to see if a file exists on a particluar server
2. if it does not then create the file with some contents.
I have read a number of articles about checking safe_mode etc and the server I am using, which is where all the files that I want to write to exists has the following settings:-
allow_url_fopen = On
allow_url_include = Off
file_uploads = On
safe_mode = Off
The server where I am running the script is the same server where I want to write the files to.
So I started to use
$FileToCheck = "http://www.mysite.com/Admin/test.php";
if (!file_exists($FileToCheck)) {echo "File " . $FileToCheck . " Does Not Exists";}
This always returns false even is the file exists.
So I tried another method as follows:
$FileToCheck = "http://www.mysite.com/Admin/test.php";
if($handle = fopen($FileToCheck, 'x+')) {echo "File Opened OK</br>";}
This always returns true even if the file does not exist.
So now I am confused and need some help on whether I need to check other php.ini setting or
why file_exists and fopen are not doing what I am expecting
Thanks in Advance.
Problems writing file to server using fopen/file_exists
Moderator: General Moderators
-
TonyBunney
- Forum Newbie
- Posts: 7
- Joined: Thu Jul 30, 2009 8:26 am
Re: Problems writing file to server using fopen/file_exists
you cant use file_exists to check a file on another server, has to be on the local, same for fopen.
I had the same problem, the quick way i founf(hacky quick way) was to use file_get_contents(). Off the top of my head like the following:
I had the same problem, the quick way i founf(hacky quick way) was to use file_get_contents(). Off the top of my head like the following:
Code: Select all
if(@file_get_contents("http://www.google.com") {
//exists
}else{
//dont exists
}
Re: Problems writing file to server using fopen/file_exists
That's not true. If you have "allow url fopen" set to "on" in php.ini, you can open remote files with fopen(), the same as file_get_contents().towerspl wrote:same for fopen.
Re: Problems writing file to server using fopen/file_exists
well you learn something new everyday
Re: Problems writing file to server using fopen/file_exists
Well, as far as I know. Here's some more info if you're interested though: http://uk3.php.net/manual/en/filesystem ... -url-fopen
Regards,
Jack.