Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP显示来自链接的图像_Php - Fatal编程技术网

PHP显示来自链接的图像

PHP显示来自链接的图像,php,Php,我试图在通过链接单击时显示我的图像。但是,当我单击链接时,它会找到url链接中显示的图像id ok,但不会显示任何图像。你能帮忙吗 <?php //sets up thisPage $pageSize=10; if (isset($_POST["thisPage"])) $thisPage=$_POST["thisPage"]; else $thisPage=1; //selects all distinct expenses that have

我试图在通过链接单击时显示我的图像。但是,当我单击链接时,它会找到url链接中显示的图像id ok,但不会显示任何图像。你能帮忙吗

 <?php

//sets up thisPage          
 $pageSize=10;
  if (isset($_POST["thisPage"])) $thisPage=$_POST["thisPage"];
   else $thisPage=1;



 //selects all distinct expenses that have been uploaded
 $dbQuery="SELECT * FROM images WHERE user_id = '$userID' ";

  $dbResult=mysqli_query($db_connection, $dbQuery) or die(mysqli_error($db_connection));
  echo "<table cellspacing=\"5\" class=\"recordsTableBG\"> <thead 
  class=\"recordsTableHeader\">";
  echo '<tr>     <th>ID</th><th>Amount</th><th>Description</th><th>Filename</th>
   <th>Project ID</th><th>Status</th></tr></thead>';
    echo '<tr class="alternateRowColor">';

   '<tr>';
    while ($dbRow=mysqli_fetch_array($dbResult)){

    echo "<img src = 'uploaded/$image' width = '200' height = '200'>";

  // display row with expense
  echo '<td>'. $dbRow['id'] .'</td>';
 echo '<td>'. $dbRow['user_id']. '</td>';
     echo '<td><a href='.$_SERVER['PHP_SELF'].'?imageid='.$dbRow['id'].'>
Click here to view image</a></td>';
    }
 echo "</table>";
 echo "</form>";



   ?>



    <!-- add submitt button
            close form  -->

       </div>

这里混合了两种方法,这就是困惑所在

首先,注意你的

<img src='uploaded/$image' width = '200' height = '200'>

浏览器将看到如下内容

<img src='uploaded/picture_of_cat.jpg' width='200' height='200'>
<a href='http://example.com/index.php?imageid=1234'>Click here to view image</a>

并渲染一张200px x 200px的猫图像。我猜那是你的缩略图。(顺便说一句,我注意到它没有包含在
中,即使它在表行中)

在桌子的另一部分,你有

<a href='.$_SERVER['PHP_SELF'].'?imageid='.$dbRow['id'].'>Click here to view image</a>

它将呈现为

<img src='uploaded/picture_of_cat.jpg' width='200' height='200'>
<a href='http://example.com/index.php?imageid=1234'>Click here to view image</a>

当用户单击该链接时,它将向服务器发出
GET
请求,请求
imageid
等于1234。服务器将如何处理该
imageid
?在你发布的代码中,没有任何内容

你有两个选择:

  • 如果希望保持链接的原样,则必须编写一些代码,以获取
    imageid
    值,找到适当的图像,并将其作为图像数据返回到浏览器——这意味着设置适当的标题并将数据作为二进制数据发送回去

  • 更简单的方法是将链接中的URL替换为
    标记中的URL-当用户单击它时,服务器将返回图像


  • 您在哪里为
    $image
    变量设置值?我应该使用类似于echo“”的东西吗$dbRow['image'].';?是的,在img标记中,例如:
    echo'(假设图像在上传文件夹中)您的“单击此处”链接将有一个类似
    http://localhost/index.php?imageid=1234
    。在上面的脚本中,我没有看到任何将从
    $\u GET
    数组中获取
    imageid
    值并返回图像数据的内容。我尝试了echo“”;但它似乎不起作用