PHP can't write to files?

O

old.PhantomSnake

Guest
I'm learning PHP and I'm trying to make a browser kind of thing... That's not important... But my scripts can't seem to be able to write to files or create folders or rename stuff. For example, something simple like this wont work:

PHP:
$f = fopen("http://www.phantom.barrysworld.net/test.html", "w");
fputs($f, "Test!");
fclose($f);

I know the code is right. PHP seems to work in every other way (ie. I can open files and read data from them). Is this something Barrysworld does on purpose for security reasons or something? What's going on? I need to be able to write files... ='(
 
O

old.PhantomSnake

Guest
I just realised something. I can write a file if I open it on FTP, like:

PHP:
$f = fopen("ftp://phantom:password@hosted.barrysworld.net/test.html", "w");

This does work, but it's slow because it has to connect to the FTP. Isn't there a better way to do it, as a server-side operation so that logging in is not required?
 
T

Tempy_Incursion

Guest
Maybe you could try omitting the site address and just using "test.html". :)
 
O

old.PhantomSnake

Guest
I have tried that. It still doesn't work. PHP gives no error of any sort (I haven't even seen PHP give an error before) but the file isn't created.
 
T

Tempy_Incursion

Guest
I've never had any real problems when writing to files, I did it as usual earlier with a new script ive made and it saved everytime. :confused:

Also, error display is disabled on BW :(
 
O

old.PhantomSnake

Guest
Can you please email me the script please? If you don't want to share your code, cut out all the extra stuff so I can at least still see the save part. Maybe I'm only making a small stupid mistake. =| My email is phantom_snake@cogeco.ca . Thanks.
 
O

old.PhantomSnake

Guest
Tempy_Incursion has helped me solve the problem, and now I got it figured out. This is just a summary for the record. :D

By attempting to save to a file using only the relative path (that is, without the http://... part) you can save to folders that are chmodded 777. You can't save to your root folder (at least I can't), unless you are overwriting a file that is already there and is chmodded 666.

That mean that this will work:

Code:
$f = fopen("test.html", "w");

But only if the file test.html already exists and is chmodded 666! Otherwise, if you want to create a new file, you have to save to a subfolder that is chmodded 777.

There. Crystal clear, isn't it? :rolleyes:
 
T

Tempy_Incursion

Guest
Yeap that seems to sum it up quite nicely Phantom! :D
 
O

old.korngurl

Guest
i'm having the same problems with saving....

how do you chmod a file to 666 or whatever?

bleh... i'm confused on what to do still, so if you could help me i would greatly appreciate it!
 
O

old.PhantomSnake

Guest
Chmodding files/folders is easiest with an FTP program. I recommend CuteFTP but most likely any program of this kind will have the chmod function. Just select the file you want to chmod and select the chmod function (which would differ from program to program) and you get a dialog asking for the options. Just type in the number 666 and go.

I took a screenshot of how this is done with CuteFTP. I hope this helps.

chmod.gif
 

Users who are viewing this thread

Top Bottom