PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Sun Sep 05, 2004 11:35 am
Hey there ppl, i'm trying to make a 'content displayer' for my site, that loads *.inc files via index.php?page=bla.
This is my script:
Code: Select all
if (isset($_REQUEST['page']))
{
$inc = $_REQUEST['page'].".inc";
if (!file_exists($inc))
{
$content = "Page not found";
}
else
{
$file = file($inc);
$fp = fopen($inc, "w");
fclose($fp);
$content = $fp;
}
}
else
{
$file = file("main.inc");
$fp = fopen("main.inc", "w");
fclose($fp);
$content = $fp;
}
I get no errors with this (although it doesn't display what it's supposed do) i just get the message 'Resource id #3' where the content should be..
Any ideas ? Cus i have no clue what this means, and when i search for other examples, it's all to do with database things...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 05, 2004 11:54 am
your content is getting a file pointer. you want the content of the file? use [php_man]file_get_contents[/php_man], [php_man]file[/php_man], or [php_man]fread[/php_man].
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Sun Sep 05, 2004 12:31 pm
ok, i tried using fread (cus it seemed simple lol) this is what i got:
Code: Select all
if (isset($_REQUEST['page']))
{
$inc = $_REQUEST['page'].".inc";
if (!file_exists($inc))
{
$content = "Page not found";
}
else
{
$handle = fopen($inc, "r");
$contents = fread($handle, filesize($inc));
fclose($handle);
$content = $contents;
}
}
else
{
$handle = fopen("main.inc", "r");
$contents = fread($handle, filesize("main.inc"));
fclose($handle);
$content = $contents;
}
But i get this error:
Warning: fread(): Length parameter must be greater than 0. in ***\game.php on line 29
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 05, 2004 12:34 pm
the files have zero size.
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Sun Sep 05, 2004 12:36 pm
i don't understand..., in 'main.inc' i just have a line of text saying Hello...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Sep 05, 2004 12:39 pm
your previous code had w passed to fopen.. this will truncate the file to zero bytes. Are you sure main.inc has "Hello" ?
Getran
Forum Commoner
Posts: 59 Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:
Post
by Getran » Sun Sep 05, 2004 12:40 pm
ah i see now, yeh it had set the to 0 bytes
[SOLVED]