【问题标题】:Picture can't be displayed in php [closed]图片无法在php中显示[关闭]
【发布时间】:2012-12-22 05:17:27
【问题描述】:

我正在创建一个函数,在插入用户名后将从数据库中检索用户显示图片。但我的代码遇到了一些问题。请帮我看看^^ 非常感谢。

<?php
include("connection.php");

$name = $_SESSION['login_username']; // login_username is test123, this is $_SESSION from another .php file
$_SESSION['name'] = $storename;


echo '<img src="display2.php"width="90" height="90"/>'; //this is how i display my picture
?>

Display.php(不工作)

mysql_select_db($database) or die("Can not select the database: ".mysql_error());

$storename = $_SESSION['name']; // is there an error with my $_session statement?
$name = (string)$storename; 

if(!isset($name) || empty($name)){
     die("Please select your image!");

}else{


$query = mysql_query("SELECT * FROM customerdetail WHERE customer_username='$name'");
$num_row = mysql_fetch_array($query);
$content = $num_row['image'];

header('Content-type: image/jpg');
echo $content;

 }
}   

Display.php(工作)

    $storename = "test123"; // it worked if i store the id in string but not passing from another page.
    $name = (string)$storename;

if(!isset($name) || empty($name)){
     die("Please select your image!");
}else{

$query = mysql_query("SELECT * FROM customerdetail WHERE customer_username='$name'");
$row = mysql_fetch_array($query);
$content = $row['image'];

header('Content-type: image/jpg');
         echo $content;

}
?>  

谁能帮我弄清楚出了什么问题?提前致谢。

【问题讨论】:

  • 它有什么问题? “出了点问题”不是错误描述。
  • 看起来你在第一个文件中的$_SESSION['name'] = $storename; 是空的,从文件 cmets 你说在 // login_username is test123 上面的一行,在最后一个(工作)文件中你说你想要 $storename;具有价值"test123"。可能是一个错字,并在您的第一行文件中将 $name = $_SESSION['login_username']; 更改为 $storename = $_SESSION['login_username'];

标签: php session post get


【解决方案1】:

在您的 php 文件(两个)的最顶部,放置这行代码(当然是在 &lt;?php 标记之后):

session_start();

【讨论】:

  • 是的,我已经将它包含在我的“connection.php”中了^^
  • 好的。我看到你试图在 display2.php 中显示图像,而你的脚本在 display.php
  • 谢谢 ~~ 我真的错过了 display.php 中的 session_start()。如此愚蠢的错误..大声笑
【解决方案2】:

header('Content-type: image/jpg'); 声明输出将是 jpg 图像,因为代码从 &lt;img src=""&gt; 运行

无法将文本显示为图片

【讨论】:

  • 对不起,我不擅长编程,你能详细解释一下吗?非常感谢^.^
  • 不就是显示图片的正确方法吗?
  • 如果是这样,如果你不包含那一行,那么输出类型将是 text/html (CMIIW),当然你不能使用 img 标签“调用”html文件.如果你包含它,所以类型是图像,它可以工作!
  • 我英语不好,如果单词不好,请见谅
  • 没关系。你能举个例子吗?因为我真的不明白。如果我为 &storename 分配值,它可以工作。当我将上一页的另一个值传递给 $storename 时,它​​根本无法工作。 PS:我确实将值从 login1.php 传递到 login2.php。但是当我将值从 login2.php 传递给 display.php 时。好像有错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 2019-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多