Page 1 of 1

fopen won't work with url but works with server path

Posted: Tue Aug 16, 2005 6:46 pm
by chemoul
Hi,

I have a problem with the following code:

Code: Select all

$myFile = $siteurl."feed.xml";
echo "myfile: $myFile";
$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $feeddata);

fclose($fh);
If $siteurl is a URL, such as http://www.myserver.com/feeddirectory/, then I get the error "can't open file". The URL that is echoed by the script is correct, if I copy and paste the URL in my webbrowser it displays the xml file.
The same script works if I use the local path on the server instead, ie. /usr/home/feeddirectory/, but that's not really an option for my script.
allow_url_fopen is set to 'on' on the server. What's more, the same problem occurs on my local testserver (windows xp) and on my remote server (linux). The above php code and the feed.xml file are in different directories on the server but I don't really see how this could cause the problem.

Does anyone have any ideas, because this is starting to drive me nuts.

Thank you for your replies.

Stefan

Posted: Tue Aug 16, 2005 7:04 pm
by feyd
url wrappers are off it sounds..

http://php.net/ref.filesystem#ini.allow-url-fopen

Posted: Tue Aug 16, 2005 7:22 pm
by chemoul
as I said

"allow_url_fopen is set to 'on' on the server"

Posted: Tue Aug 16, 2005 7:29 pm
by feyd
still sounds like it's actually off.. you may want to check if http is a registered stream

Posted: Tue Aug 16, 2005 7:33 pm
by timvw
http://php.belnet.be/manual/en/wrappers.http.php says:
Allows read-only access to files/resources via HTTP 1.0, using the HTTP GET method

So you should consider using FTP(S)/SCP if you want to write.

Posted: Tue Aug 16, 2005 7:35 pm
by chemoul
wow, this is turning into a chat.. thank you for your prompt responses :-)
The information that the url wrapper is on is taken from phpinfo, where it says

Configuration, PHP Core

Diretcive Local Value Master Value
allow_url_fopen On On

How do I check whether http is a registered stream?

Thank you for your help.

Posted: Tue Aug 16, 2005 7:36 pm
by chemoul
Hi Timvw

your resource actually says "HTTP connections are read-only; you cannot write data or copy files to an HTTP resource."

Bugger...

Posted: Tue Aug 16, 2005 7:40 pm
by feyd
damn.. I completely missed the "write" request.. :lol:

:oops:

Posted: Tue Aug 16, 2005 7:47 pm
by chemoul
But then I get the error msg during fopen and not when I'm trying to write to the file...
Admittedly, this won't solve my problem with writing to the file, but why won't it even open the file?

... ok... the 'w' flag in fopen..

Posted: Tue Aug 16, 2005 7:49 pm
by nielsene
You are asking to open the file in "write mode" which has to erase the file first. So if you don't have write capability, you can't even open the file. If you want to test remote opening, change the 'w' to a 'r' to see if the open succeeds.