Page 1 of 1

[SOLVED] Resource id #3

Posted: Sun Sep 05, 2004 11:35 am
by Getran
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...

Posted: Sun Sep 05, 2004 11:54 am
by feyd
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].

Posted: Sun Sep 05, 2004 12:31 pm
by Getran
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

Posted: Sun Sep 05, 2004 12:34 pm
by feyd
the files have zero size.

Posted: Sun Sep 05, 2004 12:36 pm
by Getran
i don't understand..., in 'main.inc' i just have a line of text saying Hello...

Posted: Sun Sep 05, 2004 12:39 pm
by feyd
your previous code had w passed to fopen.. this will truncate the file to zero bytes. Are you sure main.inc has "Hello" ?

Posted: Sun Sep 05, 2004 12:40 pm
by Getran
ah i see now, yeh it had set the to 0 bytes :P

[SOLVED]