Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trying to write to a file from within an html page...

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
Code:
<?php
$filename = "test.txt";
$fp = fopen( $filename, "w" ) or die("Couldn't open $filename");
fwrite( $fp, "Hello world\n" );
fclose( $fp );
?>

this is the code i'm using...and i have a file that is named test.txt saved in the same directory that the html file carrying the above php script is in...

it's not working...

any ideas?

- g
 
What do you mean by "from within an HTML page"?

You don't mean that this file's filename extension is ".html" or ".htm", do you? If you're running this through a web server, you'll have to either rename this file to a ".php" extension or reconfigure your server to execute .html files.


Other than that, most problems writing to files are permission problems. That script will be run as some user, either the user that explicitly invokes PHP through the command line or the username as which your web server runs. Does that user have permission to write to this file?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top