Jump to content

Include with $_GET variables won't find file?


Mutley

Recommended Posts

When I do this:

<?php include("find.php?team=".$team."&subject=".$subject.""); ?>

I get this error:
Warning: main(find.php?team=1&subject=2006) [function.main]: failed to open stream: No such file or directory in

However if I goto the file with my browser address, like www.mysite.com/find.php?team=1&subject=2  ...it works? Anyone know why?
Link to comment
Share on other sites

Yeah, it's because you try to include a file on the filesystem that is actually called "find.php?team=1&subject=2000", but there is not a file called that. When you type the url you tell the server to load "find.php", which exists, then the rest is parsed as GET variables.

If you want the output of of what you include, then just do this: [code]<?php echo file_get_contents("http://www.mysite.com/find.php?team={$team}&subject={$subject}"); ?>[/code] or if you want to include the file, but have some variables set, then just set the variables before and then include find.php
Link to comment
Share on other sites

[quote author=Mutley link=topic=108510.msg436610#msg436610 date=1158597409]
How can I do this then? Any fix of some sort?

I need it to include a file with the variables in the URL.
[/quote]

No, you need something that works.  That might be a [i]partial copy[/i] of find.php that accepts variable already declared, e.g.

[code]<?php
$team = 1;
$subject = 2000;
include("the_working_part_of_find.php");[/code]
Link to comment
Share on other sites

Thanks alot! I've got that to work now but I have a similar problem here in a FUNCTION:

[code]{
echo "<a href=\"http://www.mysite.com/galleryfind.php?team=$team&subject=2006&game={$item}\"\n>{$item}</a> <br />";
}[/code]

As you can see, {$item} is some variable and also $team but obviously this doesn't work, I just get a same error as before when I goto that page but I don't know how to get {$item} to work.

I tried this:

[code]{
?><a href="http://www.mysite.com/galleryfind.php?team=<?=$team?>&subject=2006&game=<?={$item}?>"><?={$item}?></a> <br /><?php
}[/code]

But can't seem to get it to work at all. :(

Link to comment
Share on other sites

Yep, sorted that. Now finally, one more problem. This doesn't make sense:

[code]$team = $_GET['team'];
$game = $_GET['game'];

echo $team;
echo $game;[/code]

For some reason, if I do ?team=1&game=test ...it doesn't show the game? Why? It just doesn't seem to recognise it, so I can't use it when doing URLs further down:
$thumbnail_folder = "./gallery/images/".urlencode($team)."/2006/".urlencode($game)."/thumbs";

It just loads as gallery/images/1/2006//thumbs  ???

Thanks alot Orio.

Link to comment
Share on other sites

Nope, won't work, it won't find the "game" variable, if I echo it nothing appears. Heres the whole file:

[code]<table align="center" cellpadding="5">

<?
$build = false;
if(isset($HTTP_GET_VARS["b"]) || isset($HTTP_GET_VARS["build"]))
  $build = true;

$image = ""; 
if(isset($HTTP_GET_VARS["image"]))
  $image = $HTTP_GET_VARS["image"];

$team = $_GET['team'];
$game = $_GET['game'];
//$match = $_GET['match'];
//echo $match;
echo $team;
echo $game;
$thumbnail_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."/thumbs";
$thumbnail_width = 160; $thumbnail_height = 120;

$image_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."";
$image_width = 640; $image_height = 480;

$source_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."";

//The number of thumbs in a row,
//followed by the number of rows in a page.
$row_size = 3;
$page_size = 5;

$row = $HTTP_GET_VARS["row"];
if($row == "")
  $row = 0;

if(is_dir($thumbnail_folder) == false)
  mkdir($thumbnail_folder, 0755);
 
if(is_dir($image_folder) == false)
  mkdir($image_folder, 0755);
 
if(is_dir($source_folder) == false)
  mkdir($source_folder, 0755);


if($build == true)
  {
  //Get an array of all the jpg files in the current source directory.
  $source_files = glob($source_folder . "/*.JPG");
 
  for($index = 0; $index < count($source_files); $index++)
    {
    $original_jpg = imagecreatefromjpeg($source_files[$index]);
    $original_size = getimagesize($source_files[$index]);
    $original_width = $original_size[0]; $original_height = $original_size[1];
   
    $source_file_name = substr($source_files[$index], strrpos($source_files[$index], "/") + 1);
   
    $thumbnail_jpg = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
    imagecopyresized($thumbnail_jpg, $original_jpg, 0, 0, 0, 0,
                      $thumbnail_width, $thumbnail_height, $original_width, $original_height);
    imagejpeg($thumbnail_jpg, $thumbnail_folder . "/" . $source_file_name);
    imagedestroy($thumbnail_jpg);
   
    $image_jpg = imagecreatetruecolor($image_width, $image_height);
    imagecopyresized($image_jpg, $original_jpg, 0, 0, 0, 0,
                      $image_width, $image_height, $original_width, $original_height);
    imagejpeg($image_jpg, $image_folder . "/" . $source_file_name);
    imagedestroy($image_jpg);
                           
    imagedestroy($original_jpeg);
    }
  }
?>

<?
//Get an array of all the jpg files in the current thumbnail directory.
$thumbnail_files = glob($thumbnail_folder . "/*.JPG");
$first_index = $row * $row_size;
$last_index = $first_index + $page_size * $row_size;
if($last_index > sizeof($thumbnail_files))
  $last_index = sizeof($thumbnail_files);

for($index = $first_index; $index < $last_index; $index++) {
?>

<? if($index == $first_index) { ?>
<tr>
<? } ?>

<? if($index != 0 && $index % $row_size == 0 && $image == "") { ?>
</tr><tr>
<? } ?>

<?
$image_file = substr($thumbnail_files[$index], strrpos($thumbnail_files[$index], "/") + 1);
$image_url = "gallerytest.php?row=" . $row . "&image=" . $image_file;
?>

<? if ($image == "") { ?>
<td>
<a onclick="window.open(this.href, 'popupwindow', 'width=700,height=600,scrollbars,resizable'); return false;" href="<?= $image_url ?>">
<img src="<?= $thumbnail_files[$index] ?>" border="3" style="border-color:aa5500;" /></a></td>
<? } ?>

<?
$next_index = $index + 1;
if($next_index >= $last_index)
  $next_index = $first_index;
$next_image_file = substr($thumbnail_files[$next_index],
                          strrpos($thumbnail_files[$next_index], "/") + 1);
?>

<!--^ Get Next Image ^-->

<? if($image == $image_file) { ?>
<td colspan="2">
<a href="gallerytest.php?row=<?= $row ?>&image=<?= $next_image_file ?>">
<img src="<?= $image_folder . "/" . $image_file ?>" border="3" style="border-color:aa5500;" /></a>
<br />
<center><a href="javascript:window.close();">Click here to close this Window</a></center>
</td>
</tr>

<!--^ Image full size pop-up ^-->

<?
$previous_index = $index - 1;
if($previous_index < $first_index)
  $previous_index = $last_index - 1;
$previous_image_file = substr($thumbnail_files[$previous_index],
                              strrpos($thumbnail_files[$previous_index], "/") + 1);
?>

<!--^ Get Previous Image ^-->

<tr>
<td>
<a href="gallerytest.php?row=<?= $row ?>&image=<?= $previous_image_file ?>"><b>Previous Image</b></a>
</td>

<td align="right">
<a href="gallerytest.php?row=<?= $row ?>&image=<?= $next_image_file ?>"><b>Next Image</b></a>
</td>
<? } ?>

<? if($index == count($thumbnail_files) - 1) { ?>
</tr>
<? } ?>

<? } ?>

<? if($image == "") { ?>
<tr>
<td colspan="<?= $row_size ?>">
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
<?
$previous_row = $row - $page_size;

$last_page_size = ceil(sizeof($thumbnail_files) / $row_size) % $page_size;
if($last_page_size == 0)
  $last_page_size = $page_size;

if($previous_row < 0)
  $previous_row = ceil(sizeof($thumbnail_files) / $row_size) - $last_page_size;
?>
<a href="gallerytest.php?row=<?= $previous_row ?>">Previous Page</a>
</td>

<td align="right">
<?
$next_row = $row + $page_size;
if($next_row >= ceil(sizeof($thumbnail_files) / $row_size))
  $next_row = 0;
?>
<a href="gallerytest.php?row=<?= $next_row ?>">Next Page</a>
</td>
</tr>
</table>
</td>
</tr>
<? } ?>
</table>[/code]

If I goto ?team=1&game=test

It will load the team variable but not game.
Link to comment
Share on other sites

This:
[code]<?
$build = false;
if(isset($HTTP_GET_VARS["b"]) || isset($HTTP_GET_VARS["build"]))
   $build = true;

$image = "";   
if(isset($HTTP_GET_VARS["image"]))
   $image = $HTTP_GET_VARS["image"];

$team = $_GET['team'];
$game = $_GET['game'];
//$match = $_GET['match'];
//echo $match;
echo $team."<br>";
echo $game;

?>[/code]

Gives me the output as it should be... See for yourself:
http://www.oriosriddle.com/test.php?team=1&game=test (EDIT- deleted test.php)

Orio.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.