PHP -获取带有文件扩展名的请求变量不起作用


PHP - Getting request variable with a file extension doesn't work

$badgedata = $_GET['badge'];
if ($badgedata == "test.gif") {
  $im = imagecreatefromgif("badges/base/test.gif");
  imagegif($im);
}

为什么当我转到

时显示空白页
badge.php?badge=test.gif

但如果我尝试

$badgedata = $_GET['badge'];
if ($badgedata == "test") {
  $im = imagecreatefromgif("badges/base/test.gif");
  imagegif($im);
}

转到

badge.php?badge=test

它工作,但我需要.gif在最后。

你试过了吗?

URL

?badge=test%2Egif

代码
<?php
$badge = (isset($_GET['badge'])) ? urldecode($_GET['badge']) : null;
if(!empty($badge))
echo $badge;

必须设置header

$badgedata = $_GET['badge'];
if ($badgedata == "test.gif") {
   $im = imagecreatefromgif("badges/base/test.gif");
   header('Content-Type: image/gif');
   imagegif($im);
}

检查徽章值

$badgedata = $_GET['badge'];
echo $badgedata;