Forum Moderators: coopster

Message Too Old, No Replies

PHP Includes

Including a PHP file with parameters

         

NancyJ

11:29 am on Nov 20, 2004 (gmt 0)

10+ Year Member



Hi, I have a small question about php includes...

I'm trying to include a php file but at the same time pass a variable with the url

include("download.php?file=$file");

The error message I get is "Warning: Failed opening 'download.php?file=' for inclusion"

How do I overcome this? Or is it not possible to do?

NancyJ

11:42 am on Nov 20, 2004 (gmt 0)

10+ Year Member



I changed the syntax slightly to use single quotes, now it reads the full address but it still cant open the file.
Without the?file=$file it opens it fine :S

henry0

12:13 pm on Nov 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



NancyJ, welcome on WebMasterWorld

have a look
Here [us2.php.net]

NancyJ

12:31 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



Thanks!

Solved that little problem, still not getting the result I want though :(

This is my download.php

<?php
$file = $HTTP_GET_VARS['file'];

echo "<img src = \"$file\">";

?>

However I'm not getting an image displayed. I get the image box and the properties has my domain followed by $file rather than the actual file name and path. I checked the address bar and that is showing the right file

henry0

1:01 pm on Nov 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might need overcoming some earlier PHP coding practices and use:
(Check your php.ini)
// PHP5 with register_long_arrays off?
if (!isset($HTTP_POST_VARS) && isset($_POST))
{
$HTTP_POST_VARS = $_POST;
$HTTP_GET_VARS = $_GET;
$HTTP_SERVER_VARS = $_SERVER;
$HTTP_COOKIE_VARS = $_COOKIE;
$HTTP_ENV_VARS = $_ENV;
$HTTP_POST_FILES = $_FILES;
}

NancyJ

1:26 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



I have used $HTTP_GET_VARS before without any problems...

Salsa

2:44 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



Welcome Nancy. When you initially set $HTTP_GET_VARS['file'], including the file's path, are you using a backslashed directory path? If you backslash the $ before a variable, like \$file, it'll literally echo '$file' rather than the value of $file. That's the first thing I'd think here. If your path string has a backslash immediately before a variable, concatenate it like "path\".$file;

NancyJ

3:06 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



My main file says this:
$file = $HTTP_GET_VARS['file'];
include 'http://sims2.hazelryan.co.uk/download.php?file=$file';

I echoed the $file before the include and it comes out fine

but when it passes through to download.php it goes wrong

<?php
$file = $HTTP_GET_VARS['file'];

echo "<img src = \"$file\">";

?>

Birdman

3:40 pm on Nov 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World, Nancy!

I may be missing something here. What is the point of including a file to simply echo a variable? If that's the full contents of download.php, then it's just not worth putting in a separate file.

why not just use this directly in the script:

if ( isset($_GET['file']) ) print '<img src=' . $_GET['file'] . ' />';

If you still wish to include the simple echo script, then you should be able to do so by simply setting the var in the main script. The include will have access to the var, along with any other vars in the main script.

Salsa

3:52 pm on Nov 20, 2004 (gmt 0)

10+ Year Member



I guess I'm still not sure what you're wanting to do here either, Nancy.

You may want to look again at the link that henry0 gave you in msg# 3.

Are you actually wanting to include all of the file, download.php, within your script, or are you just wanting to create an image tag that reads:

<img src="http://yoursite.uk/download.php?file=value">

If you are just wanting to create a tag, try:

$file = $HTTP_GET_VARS['file']; 
$tag = "<img src=\"http://yoursite.uk/download.php?file=$file\">";
echo $tag;