Tom83B
Tom83B

Reputation: 2099

php failed to open stream - no such file or directory

I have the following php code:

<html><body>

    <?php include('scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); ?>
</body>
</html>

You can see the result here: http://apps.facebook.com/krajecr/pokus2.php

As you can see, it tells me, that it doesn't exist. But if I use just the link: http://apps.facebook.com/krajecr/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML it works fine an I see exactly what I want to see. Where is the problem please?

Upvotes: 0

Views: 1133

Answers (4)

Lightness Races in Orbit
Lightness Races in Orbit

Reputation: 385134

As the error says, "scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML" is not a file or directory. Just because you can enter querystring parameters ("?" and after) into your web browser does not mean that these are part of the filename. The filename is scores.php.

It looks like you want to go and make a request through a webserver rather than just opening a local file. Fortunately, include allows that natively too. However, you have to specify it:

<html>
  <body>
    <?php include('http://someserver.com/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); ?>
  </body>
</html>

Alternatively (and preferably, to save an HTTP request), if scores.php is on the same webserver, you can access it as a normal file but set the $_GET parameters beforehand, as these will survive through the include directive:

<html>
  <body>
    <?php
    $_GET = Array('filename' => 'scores/score.sco'); // add the others here too
    include('scores.php');
    ?>
  </body>
</html>

Hope that helps.

Upvotes: 2

Naftali
Naftali

Reputation: 146302

you cannot do an include with get values.

you can set all ur ness get values with

$_GET[..] = ...

and then do

include('scores.php')

Upvotes: 0

RedSoxFan
RedSoxFan

Reputation: 634

As far as I know, you cannot use an include with parameters, it must be a file name. You can set the $_GET['var'] = 'value'; before your call to include for a way that does work.

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798576

The problem is that you've specified it as an access via the filesystem, when you actually need to have it access via the web server. Put in the full URL.

Better yet, convert the script to include into a function and then include and call it.

Upvotes: 0

Related Questions