469,929 Members | 2,104 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

file_put_contents problem

Hello everybody,

I'm trying to get a file on the internet and put it on my server...

So, from javascript (AJAX) a call a php function that is simply:

file_put_contents('RSS_news/bbc.xml', file_get_contents('http://
newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml'));

file_get_contents doesn't seem to give any problem...

anyway, this is the response I get:
"<br />

<b>Warning</b>: file_put_contents(RSS_news/bbc.xml) [<a
href='function.file-put-contents'>function.file-put-contents

</a>]: failed to open stream: No such file or directory in <b>/var/www/
Eclipse/thebigone/server_scripts

/rss_bbc.php</bon line <b>9</b><br />"

and line 9 of that file is exactly the unique row of code:
file_put_contents('RSS_news/bbc.xml', file_get_contents('http://
newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml'));

My PHP Version is 5.2.3-1

any idea?!?

thanks in advance
Andrea

PS: the unique thing I need to do with this function is take a file on
the internet and copying it on my server... and then I'll do something
else...
Jun 27 '08 #1
5 10718
^AndreA^ escribió:
<b>Warning</b>: file_put_contents(RSS_news/bbc.xml) [<a
href='function.file-put-contents'>function.file-put-contents

</a>]: failed to open stream: No such file or directory in <b>/var/www/
Eclipse/thebigone/server_scripts

/rss_bbc.php</bon line <b>9</b><br />"
Does PHP have permission to create files in
"/var/www/exist/Eclipse/thebigone/server_scripts"? If PHP runs as Apache
module then the "server_scripts" directory needs to have write
permission for the user Apache runs as (typically "nobody" or "apache").

You can probably change permissions with your FTP client. I suggest you
create a special folder for these downloads so you don't need to make
server_scripts itself writable.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #2
On Jun 25, 9:23 pm, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
^AndreA^ escribió:
<b>Warning</b>: file_put_contents(RSS_news/bbc.xml) [<a
href='function.file-put-contents'>function.file-put-contents
</a>]: failed to open stream: No such file or directory in <b>/var/www/
Eclipse/thebigone/server_scripts
/rss_bbc.php</bon line <b>9</b><br />"

Does PHP have permission to create files in
"/var/www/exist/Eclipse/thebigone/server_scripts"? If PHP runs as Apache
module then the "server_scripts" directory needs to have write
permission for the user Apache runs as (typically "nobody" or "apache").

You can probably change permissions with your FTP client. I suggest you
create a special folder for these downloads so you don't need to make
server_scripts itself writable.

--
--http://alvaro.es- Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
First confirm, the file (in which you are trying to put the xml
contents) is exists to the mentioned location,
if YES then, Apache should have the permission to write in that file.
(Give the write permission to the file).

Jun 27 '08 #3
On Jun 26, 6:04 am, "suhasdh...@gmail.com" <suhasdh...@gmail.com>
wrote:
On Jun 25, 9:23 pm, "Álvaro G. Vicario"

<alvaroNOSPAMTHA...@demogracia.comwrote:
^AndreA^ escribió:
<b>Warning</b>: file_put_contents(RSS_news/bbc.xml) [<a
href='function.file-put-contents'>function.file-put-contents
</a>]: failed to open stream: No such file or directory in <b>/var/www/
Eclipse/thebigone/server_scripts
/rss_bbc.php</bon line <b>9</b><br />"
Does PHP have permission to create files in
"/var/www/exist/Eclipse/thebigone/server_scripts"? If PHP runs as Apache
module then the "server_scripts" directory needs to have write
permission for the user Apache runs as (typically "nobody" or "apache")..
You can probably change permissions with your FTP client. I suggest you
create a special folder for these downloads so you don't need to make
server_scripts itself writable.
--
--http://alvaro.es-Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--

First confirm, the file (in which you are trying to put the xml
contents) is exists to the mentioned location,
if YES then, Apache should have the permission to write in that file.
(Give the write permission to the file).
I expect he'll sat it does - but is looking in the wrong place.

OP: try using the absolute path in the fn call.

C.
Jun 27 '08 #4
On Jun 26, 1:33 pm, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
On Jun 26, 6:04 am, "suhasdh...@gmail.com" <suhasdh...@gmail.com>
wrote:
On Jun 25, 9:23 pm, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
^AndreA^ escribió:
<b>Warning</b>: file_put_contents(RSS_news/bbc.xml) [<a
href='function.file-put-contents'>function.file-put-contents
</a>]: failed to open stream: No such file or directory in <b>/var/www/
Eclipse/thebigone/server_scripts
/rss_bbc.php</bon line <b>9</b><br />"
Does PHP have permission to create files in
"/var/www/exist/Eclipse/thebigone/server_scripts"? If PHP runs as Apache
module then the "server_scripts" directory needs to have write
permission for the user Apache runs as (typically "nobody" or "apache").
You can probably change permissions with your FTP client. I suggest you
create a special folder for these downloads so you don't need to make
server_scripts itself writable.
--
--http://alvaro.es-Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
First confirm, the file (in which you are trying to put the xml
contents) is exists to the mentioned location,
if YES then, Apache should have the permission to write in that file.
(Give the write permission to the file).

I expect he'll sat it does - but is looking in the wrong place.

OP: try using the absolute path in the fn call.

C.
ARGHHHHHHH... damn me!!!

thanks to your comments I found out the problem...

"/var/www/exist/Eclipse/thebigone/server_scripts" did not have write
permission for PHP... but because I didn't want write the file there
but in another folder (RSS_news) at the same lavel of
server_scripts...

So the mistake was in the path... "../RSS_news/bbc.xml" instead of
"RSS_news/bbc.xml"
file_put_contents("../RSS_news/bbc.xml", file_get_contents('http://
newsrss.bbc.co.uk/rss/newsonline_uk_edition/front_page/rss.xml'));

I don't know why I thought the path was absolute instead of
relative!!!

Cheers guys!!! ;-)
Jun 27 '08 #5
On Jun 26, 1:33 pm, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.comwrote:
On Jun 26, 6:04 am, "suhasdh...@gmail.com" <suhasdh...@gmail.com>
wrote:
On Jun 25, 9:23 pm, "Álvaro G. Vicario"
<alvaroNOSPAMTHA...@demogracia.comwrote:
^AndreA^ escribió:
<b>Warning</b>: file_put_contents(RSS_news/bbc.xml) [<a
href='function.file-put-contents'>function.file-put-contents
</a>]: failed to open stream: No such file or directory in <b>/var/www/
Eclipse/thebigone/server_scripts
/rss_bbc.php</bon line <b>9</b><br />"
Does PHP have permission to create files in
"/var/www/exist/Eclipse/thebigone/server_scripts"? If PHP runs as Apache
module then the "server_scripts" directory needs to have write
permission for the user Apache runs as (typically "nobody" or "apache").
You can probably change permissions with your FTP client. I suggest you
create a special folder for these downloads so you don't need to make
server_scripts itself writable.
--
--http://alvaro.es-Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:http://bits.demogracia.com
-- Mi web de humor al baño María:http://www.demogracia.com
--
First confirm, the file (in which you are trying to put the xml
contents) is exists to the mentioned location,
if YES then, Apache should have the permission to write in that file.
(Give the write permission to the file).

I expect he'll sat it does - but is looking in the wrong place.

OP: try using the absolute path in the fn call.

C.
C. I didn't see your post before...
relative path is fine, but... I needed the right path!!!

cheers
Andrea
Jun 27 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Michael Preminger | last post: by
reply views Thread by Börni | last post: by
20 posts views Thread by Pete Marsh | last post: by
5 posts views Thread by Mohawk Mawk | last post: by
4 posts views Thread by cookspyder | last post: by
moishy
9 posts views Thread by moishy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.