...

View Full Version : writing file problem



jakeross
07-05-2007, 10:11 PM
ok im new to php and when i say that im new i mean ive only been messin with it for a few days... so now heres my problem ive been folowing along wih a tutorial and ive got to the point that im using php to write files.. my problem is tht no matter what i do i can not get this thing to write a file.. can someone please look over the code that im using and/or give me some insigt on why i cant get this to work?



<?php

// set file to write
$file = '/php/new.txt';
// open file
$fh = fopen($file, 'w') or die('Could not open file!');
// write to file
fwrite($fh, "Look, Ma, I wrote a file! ") or die('Could not write to file');
// close file
fclose($fh);

?>

and yes i have the directory created on my server i also tried this code with no success


<?php

// set file to write
$filename = '/php/new.txt';
// write to file
file_put_contents($filename, "Look, Ma, I wrote a file! ") or die('Could not write to file');

?>



thanks,
jake

mlseim
07-05-2007, 10:25 PM
The file called "new.txt" needs to have it's permissions set to 777

When you created the file, it probably defaulted to 466, so your
script won't write to it.

Use your FTP program or online file manager (control panel) to set permissions.

jakeross
07-06-2007, 06:05 AM
ok so i changed he permissions and all that and i still cant get this to work. i know this sounds excessive but could someone write me a start to finsih in depth guide to writing a file with php? if so it would be much apperciated!

mlseim
07-06-2007, 03:30 PM
I tried your script and it works just fine for me ...



<?php

// set file to write
$file = '/php/new.txt';
// open file
$fh = fopen($file, 'w') or die('Could not open file!');
// write to file
fwrite($fh, "Look, Ma, I wrote a file! ") or die('Could not write to file');
// close file
fclose($fh);

?>


I created a directory called "php" and set permission to 777
I created "new.txt" set permission to 777

and it works just fine.

Try writing to the same directory as the script ...
$file = 'new.txt';


You must not have something configured right with your directories?

jakeross
07-06-2007, 06:15 PM
im going to try a new ftp program im using ftp explorer right now and i dont like it at all...

jakeross
07-06-2007, 07:02 PM
ok so i got it to work finally, but now i have a new question.. am i supposed to be able to see it in my ftp browser? cuz i can see it when i go to www.mysite.com/new.txt but i cant see it in the ftp window? any ideas on what this may be?

and thanks alot mlseim for all your help it really is appreciated by the newbie :)

mlseim
07-06-2007, 07:20 PM
It must be a setting in your FTP program.

I still like the outdated old WSFTP-LE ...

You can find the downloads on the web ... like here:

http://d321.k12.id.us/Support/Docs/FTP_CLIENTS/WSFTPLE/

http://www.google.com/search?hl=en&q=wsftp-le&btnG=Google+Search

It asks whether you are a student/teacher or not.
Answer yes to being a student or teacher.

It's just the very basic FTP, easy and quick.
Set a few options, like open files using Notepad (provide the path to it).

matak
07-06-2007, 07:22 PM
be sure that you are in the proper folder with your FTP explorer. EG public_html...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum