Jump to content


Photo

Include with $_GET variables won't find file?


  • Please log in to reply
17 replies to this topic

#1 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 04:27 PM

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?
~ Mutley.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 September 2006 - 04:34 PM

You don't have a file that's named find.php?team=1&subject=2000 so it can't be included.  With that in the browser address bar, you're finding find.php which then processes the information in the query string.
Legend has it that reading the manual never killed anyone.
My site

#3 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 18 September 2006 - 04:36 PM

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:
<?php echo file_get_contents("http://www.mysite.com/find.php?team={$team}&subject={$subject}"); ?>
or if you want to include the file, but have some variables set, then just set the variables before and then include find.php

#4 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 04:36 PM

How can I do this then? Any fix of some sort?

I need it to include a file with the variables in the URL.
~ Mutley.

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 18 September 2006 - 04:41 PM

How can I do this then? Any fix of some sort?

I need it to include a file with the variables in the URL.


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

<?php
$team = 1;
$subject = 2000;
include("the_working_part_of_find.php");

Legend has it that reading the manual never killed anyone.
My site

#6 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 04:59 PM

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

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

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:

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

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


~ Mutley.

#7 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 September 2006 - 05:28 PM

Try:

<?php

echo "<a href=\"http://www.mysite.com/galleryfind.php?team=".urlencode($team)."&subject=2006&game=".urlencode($item)."\">".$item."</a><br />";

?>

Orio.
Think you're smarty?

(Gone until 20 to November)

#8 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 06:18 PM

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

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

echo $team;
echo $game;

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.


~ Mutley.

#9 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 September 2006 - 06:26 PM

Use urlencode when you are making urls with get variables.
But that's a bit weird...
Try:
$thumbnail_folder = "./gallery/images/".stripslashes($team)."/2006/".stripslashes($game)."/thumbs";

Orio.
Think you're smarty?

(Gone until 20 to November)

#10 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 06:34 PM

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

<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>

If I goto ?team=1&game=test

It will load the team variable but not game.
~ Mutley.

#11 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 September 2006 - 06:39 PM

Try changing $_GET['game'] with $HTTP_GET_VARS['game']
$_GET is only supported from php4.1 or greater.

(run phpversion() to know your php version)

Orio.
Think you're smarty?

(Gone until 20 to November)

#12 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 06:43 PM

Same problem, $team works but the $game variable doesn't?  ??? It makes no sense.
~ Mutley.

#13 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 September 2006 - 06:50 PM

I have no idea...
If game is a number it does work?
If you switch the places so it'll become "?game=test&team=1" will game pass and team won't?

Orio.
Think you're smarty?

(Gone until 20 to November)

#14 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 06:52 PM

Even if switched, the $game variable doesn't work, lol. It is confusing the hell out of me, can you try it?
~ Mutley.

#15 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 September 2006 - 06:56 PM

This:
<?
$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;

?>

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

Orio.
Think you're smarty?

(Gone until 20 to November)

#16 Mutley

Mutley
  • Members
  • PipPipPip
  • Advanced Member
  • 765 posts

Posted 18 September 2006 - 07:02 PM

Fixed it, damn that was annoying.

I included it but forgot to carry the variable. So it couldn't find it.

Thanks so much Orio. Means alot.
~ Mutley.

#17 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 18 September 2006 - 07:03 PM

lol

No problem at all :)

Orio.
Think you're smarty?

(Gone until 20 to November)

#18 karthikeyan_coder

karthikeyan_coder
  • Members
  • PipPipPip
  • Advanced Member
  • 201 posts

Posted 18 September 2006 - 07:06 PM

hmm.. try to change the name "game" to "Kame" and check it for a while... just for debugging process...
www.karthi.us




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users