Help with file IO in PHP?

Axle12693

New Member
I'm just starting to learn PHP, and I'm trying out file IO. As far as I can tell, the following script is fine, but it doesn't work right.

<?php
$number = 1;
while (file_exists("post".$number))
{
$title = fopen("post".$number."/title.txt");
$createdBy = fopen("post".$number."/createdBy.txt");
$subtitle = fopen("post".$number."/subtitle.txt");
echo fread($title)."(".fread($subtitle).") was created by ".fread($createdBy);
$number++;
}
?>

When I run this, it returns "() was created by"
Yes, I have verified that all of the included files exist, and yes, all of the files have contents.
 

conor

New Member
I can't really see anything obviously wrong with that. Try adding the die command after your fopen commands to see if they are the problem. Although they shouldn't be if the text below is displaying:

Code:
fopen('file.txt') or die('could not open file.txt');

Can I ask why you are using this technique? I'm sure there would be an easier way to hold all that information...

Also have you checked your error logs? When PHP runs through an error, even if non-fatal, it logs it in the error log so that would be a good place to check.
 
Top