Click to See Complete Forum and Search --> : PHP writing to file linking docs.


Immortal
12-15-2003, 10:14 PM
I wanted these files to link and make 1 big file at news.html

here is the code:


<?php
$header = 'header.txt';
$footer = 'footer.txt';
$file = 'news.htm';
$filename = 'news.html';

$headerbuff = file_get_contents($header);
$footerbuff = file_get_contents($footer);
$filebuff = file_get_contents($file);

if(is_writable($filename)) {
if(!@file_put_contents($filename, $headerbuff.$filebuff.$footerbuff)){
echo "Unable to write to file $filename";

}else{

echo "Success writing to $filename";
}
} else {
echo "Unable to write";
}
?>

_________________________________________________

can anyone tell me why it writes nothing to the file?

pyro
12-15-2003, 10:46 PM
Do you get any error messages?

Immortal
12-15-2003, 11:03 PM
no, it dosent notify any errors

pyro
12-16-2003, 07:09 AM
What version of PHP are you using? file_put_contents requires PHP >= 4.3.0.

Immortal
12-16-2003, 04:35 PM
Alright thanks. Although is there any way that I can use fgets or something instead?

pyro
12-16-2003, 04:39 PM
Yeah, you could, but I would use file (http://us4.php.net/manual/en/function.file.php) before I'd use that...

Immortal
12-16-2003, 04:48 PM
Is there any other functions I could use?

pyro
12-16-2003, 04:58 PM
Why? What's wrong with those?

Immortal
12-16-2003, 05:00 PM
either i dont have the right php version, or its coded wrong. Either way i need a resolution

pyro
12-16-2003, 05:04 PM
To check your version of PHP:

<?PHP
phpinfo();
?>

Immortal
12-16-2003, 05:17 PM
yea, it says I have php version 4.3.3 so shouldnt it work?

pyro
12-16-2003, 05:38 PM
Get rid of the error supressor (@) before the file_put_contents function and see if you get an error.

Immortal
12-16-2003, 06:01 PM
yes i got one.

pyro
12-16-2003, 06:03 PM
Ok.

Immortal
12-16-2003, 06:13 PM
so....

pyro
12-16-2003, 06:19 PM
If you would like more help, giving me the error mesage would be a good place to start. :rolleyes: