微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php-用户ID的动态图片

如何制作一个系统,在其中提供一个userID作为GET变量并输出可以返回的图像?

例如.我将ID设为http://ccvg.net/man/findstatus.PHP?id=2

我已经创建了一些图像,并且目前使用

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        if($row["Status"] == 0){
            echo '<img src="img/currently-available.png" alt="Currently Available" height="30" width="127">';
        }
        if($row["Status"] == 1){
            echo '<img src="img/short-leave.png" alt="Short Leave" height="30" width="89">';
        }
        if($row["Status"] == 2){
            echo '<img src="img/long-leave.png" alt="Long Leave" height="30" width="89">';
        }
        if($row["Status"] == 3){
            echo '<img src="img/semi-permanent-leave.png" alt="Semi-Permanent Leave" height="30" width="160">';
        }
    }
} else {
    echo "Status not found";
}

我希望能够使用< img>标签将其显示在另一页上.

解决方法:

创建一个页面,以用于加载图像文件并允许GET.另外,请确保将内容类型设置为image / png.确保您也有GD Library installed

<?PHP
Header("Content-Type: image/png");  
//Fetch data using $_GET 
//...
$image = file_get_contents("img/undefined.png"); //new image
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        switch($row["Status"]) {
          case 0 :
             $image = file_get_contents("img/currently-available.png");
          break;
          case 1 :
             $image = file_get_contents("img/short-leave.png");
          break;
          case 2 :
             $image = file_get_contents("img/long-leave.png");
          break;
          case 3 :
             $image = file_get_contents("img/semi-permanent-leave.png");
          break;
          default :
             $image = file_get_contents("img/undefined.png"); //new image
          break;
        }
} 

$im = imagecreatefromstring($image);
imagepng($im);
imagedestroy($im);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐