Computing.Net > Forums > Programming > PHP File Write Question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

PHP File Write Question

Reply to Message Icon

Name: Bondo
Date: April 9, 2002 at 22:07:37 Pacific
Comment:

This bit of code is supposed to write a little message to a file called data.dat and then print a confirmation message saying everything went ok. Now everything works exept that when you open the file that was written to, "data.dat", there isn't a message just giberish. Anybody know why?




Sponsored Link
Ads by Google

Response Number 1
Name: Bondo
Date: April 9, 2002 at 22:08:59 Pacific
Reply:

Let me try that again:

This bit of code is supposed to write a little message to a file called data.dat and then print a confirmation message saying everything went ok. Now everything works exept that when you open the file that was written to, "data.dat", there isn't a message just giberish. Anybody know why?

/\?php

$file_name = "data.dat";
// absolute path : \home\data.dat

$file_pointer = fopen($file_name, "w");
// "w" is the mode, or the action we're
// going to perform on the file
// Detailed info at end of page

fwrite($file_pointer, "what you wanna write");
// Writing to the file, after truncating it
// to 0 bytes

fclose($file_pointer);
// everything comes to an end!

print "data written to file successfuly";

?/\



0

Response Number 2
Name: chad
Date: April 10, 2002 at 17:10:13 Pacific
Reply:

This should work...


$fp = "data.dat"; // FILE POINTER
fopen($fp, "w"); // OPEN FILE, TRUNCATE TO 0
fputs($fp, "Some text here"); // PUT DATA INTO FILE
fclose($fp); // CLOSE FILE

echo "Data written successfully to file!";
?>


(If that didn't post right, I'll try again)


0

Response Number 3
Name: Bondo
Date: April 10, 2002 at 17:49:41 Pacific
Reply:

That works perfectly. Thank you very much!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: PHP File Write Question

PHP Question www.computing.net/answers/programming/php-question/10899.html

Write to file noob question www.computing.net/answers/programming/write-to-file-noob-question/13381.html

PHP file insert www.computing.net/answers/programming/php-file-insert/11575.html