Is there a way to create and write to a new html file in php 4.1.2? I tried $file = fopen("filehere.html", "w"); but that doesn't work and mode x or x+ is only for 4.3. Any ideas on this?
| SitePoint Sponsor |

Is there a way to create and write to a new html file in php 4.1.2? I tried $file = fopen("filehere.html", "w"); but that doesn't work and mode x or x+ is only for 4.3. Any ideas on this?
php.net (fopen) doesn't list any incompatibilities with previous versions and the fopen command. 'w' should work fine -- are you sure that PHP has write permissions to that directory?
Are you getting any error messages?
My name is Steve, and I'm a super-villian.





Also note that if you don't use the full path to the file it will be created in the current working directory(cwd). At least that's how the cgi version works.Originally Posted by lieut_data
--ed

I am getting one error message:Originally Posted by lieut_data
Warning: Supplied argument is not a valid File-Handle resource in server/create.php on line 18
and heres the code for it:
I set the folder to 777. The file doesn't exsist so I thought that was the error I was getting. But maybe php can't write to the dir, what would I check to make sure?PHP Code:<?php
$word="Hi there";
$filetitle=ereg_replace (" ", "-", $word);
$dir="http://www.mypage.com/_test/";
$fileplace="$dir" . "$filetitle" . ".html";
$html ="
<html>
<head>
<title>$word</title>
</head>
<body>
Word: $word
</body>
</html>";
$file = fopen("$fileplace", "w");
fwrite($html, $file);
fclose($file);
?>





Use the local path. Something like:Originally Posted by DigitalBurn
$dir = '/home/username/www/path/to/dir/';
And it may make your life easier to not have spaces in your file names.
--ed

Tried that, now I get a new error.Originally Posted by coo_t2
Warning: fwrite(): supplied argument is not a valid stream resource
Would this mean it does have access to write to the file? Thanks for your help.





An invalid stream source suggests to me that it is the file pathname that is causing this error... as it is the pathname it's self that is the actual stream yes ?
Bookmarks