【发布时间】:2013-10-27 09:37:17
【问题描述】:
我有一个创建图像的表单(使用 imagejpeg、imagettftext 和 imagecreatefromjpeg)并将其保存在服务器的文件夹中。我需要做的是将所有创建的图像显示到另一个页面,最新的在顶部,最旧的在底部。我有一个名为 formdisplay.php 的表单,但它只是显示损坏的图像,而不是最新到最旧的。希望你能帮助我。真的需要让这个工作。提前感谢您的帮助。
我已经阅读了这些帖子,但没有一个对我有用。
Pull dedicated images from folder - show image + filename (strip part of filename + file-extension)
How can I display latest uploaded image first? (PHP+CSS)
getting images from the server and display them
Displaying images from folder in php
display image from server embedding php in html
formcreatesave.php
imagecopymerge($im, $img2, 10, 350, 0, 0, imagesx($img2), imagesy($img2), 100);
$date_created = date("YmdHis");//get date created
$img_name = "-img_entry.jpg"; //the file name of the generated image
$img_newname = $date_created . $img_name; //datecreated+name
$img_dir =dirname($_SERVER['SCRIPT_FILENAME']) ."/". $img_newname; //the location to save
imagejpeg($im, $img_dir , 80); //function to save the image with the name and quality
imagedestroy($im);
formdisplay.php
$dir = '/home3/site/public_html/Master/uploader/uploader';
$base_url = 'http://mysite.com/Master/uploader/uploader/20131027024705-img_entry.jpg';
$newest_mtime = 0;
$show_file = 'BROKEN';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (($file != '.') && ($file != '..')) {
$mtime = filemtime("$dir/$file");
if ($mtime > $newest_mtime) {
$newest_mtime = $mtime;
$show_file = "$base_url/$file";
}
}
}
}
print '<img src="' .$show_file. '" alt="Image Title Here">';
请随时编辑我的代码。谢谢:)
【问题讨论】:
-
将
print '<img src="' .$show_file. '" alt="Image Title Here">';置于$show_file = "$base_url/$file";下方 -
嗨@E L 我已经尝试过你的建议。但它仍然返回破碎的img。这一次,3张破碎的图像。请注意,我尝试显示的图像是使用 imagejpeg 和 imagecreatefromjpeg 创建和保存的。希望你能给我进一步的帮助。谢谢
-
那是因为你的
$base_url有尾文件名。让它$base_url = 'http://birdieonawire.com/Amadeus/uploader/uploader/';(真的是uploader/uploader/dirs 那里吗?) -
是的,我确定。我尝试使用 $base_url = 'birdieonawire.com/Amadeus/uploader/uploader';但它给了我 2 张破碎的图像。一个链接在错误日志中,另一个链接在我用来在创建的图像中写东西的字体中
-
那么这是
$dir的问题。尝试使用相对路径或将echo $show_file,'<br>';放在$show_file = "$base_url/$file";下方并查看它的输出。
标签: php