我正在尝试创建一个页面,供人们上传图片供所有人查看。
我正在尝试将图片存储在目录中,并通过MySQL表引用文件名。
上传我设法排序,它将文件存储在我想要的位置,并将文件名添加到表中。
它正在查看我遇到问题的图像。该页面只显示了应该是图片的空白区域,但是正确地显示了表格中的其余信息,即上传者和时间。
这是我的代码:
$myObject = new convertToAgo;
//var for gallery output
$returnstr = "";
$sql = mysql_query("SELECT * FROM pictures ORDER BY creation_date DESC");
while($row = mysql_fetch_array($sql)){
$username = $row["creator_name"];
$date = $row["creation_date"];
$file = $row["file_name"];
$convertedTime = ($myObject -> convert_datetime($date));
$whenAdded = ($myObject -> makeAgo($convertedTime));
$picture = "pictures/$file";
$returnstr .='<img src =\"$picture\" width="400px" height="400px" border="1px" />
<div class="response_top_div">Added by: ' . $username . ' | ' . $whenAdded . ' </div> <br/><br/><br/>';
}
答案 0 :(得分:1)
您的代码应如下所示
$picture = "pictures/".$file;
$returnstr .='<img src ="'.$picture.'"
或更好
$returnstr .='<img src ="pictures/'.$file.'"
答案 1 :(得分:0)
如果您拥有的$returnstr
变量准确无误,那么您实际上只是将字符串 $picture
添加到src中。你需要在变量中连接:
$returnstr .='<img src ="'.$picture.'" width="400px" height="400px" border="1px" />' ...
答案 2 :(得分:0)
您正尝试在字符串中引用变量。试试这个:
$myObject = new convertToAgo;
$returnstr = "";
$sql = mysql_query("SELECT * FROM pictures ORDER BY creation_date DESC");
while($row = mysql_fetch_array($sql)){
$username = $row["creator_name"];
$date = $row["creation_date"];
$file = $row["file_name"];
$convertedTime = ($myObject -> convert_datetime($date));
$whenAdded = ($myObject -> makeAgo($convertedTime));
$picture = "pictures/" . $file;
$returnstr .= '<img src ="' . $picture . '" width="400px" height="400px" border="1px"/>
<div class="response_top_div">Added by: ' . $username . ' | ' . $whenAdded . ' </div> <br/><br/><br/>';
}
答案 3 :(得分:0)
只有双引号可以接受php变量来将开头引号更改为双倍。
$returnstr = "<img src='$you_variable' rel='test_image' />";
希望这有效。