使用< img src ="">图片显示>不工作 [英] Image display with <img src=""> not working
问题描述
几天前,我问了关于上传图像的这个问题,满意的。我将它集成到我的网站,它没有任何问题。
我现在遇到的问题是我无法以任何形式或形式检索图像。我试图打开它们,并设置它们阅读,与fopen($ image,r)。我尝试了更复杂的东西,比如将图像加载回数据库......然后它让我感觉到anwser很简单。
我可以在我的图片文件夹中看到图片,所以应该没问题。但它不= =($ / b>
这是PHP脚本的一次,
if(isset($ _ FILES ['fupload']))
{
$ max_size = mysql_real_escape_string(strip_tags($ _ POST [ 'MAX_FILE_SIZE']));
$ file = $ _FILES ['fupload'] ['name'];
if(isset($ max_size)&&!empty($ ($ file)){
$ file_type = $ _FILES ['fupload'] ['type'];
$ tmp = $ _FILES ['fupload'] ['' tmp_name'];
$ file_size = $ _FILES ['fupload'] ['size'];
$ allowed_type = array('image / png','image / jpg',' ($ file_type,$ allowed_type)){
if($ file_size< $ max_size){
$ path ='images /'.$ file;
$ move = move_uploaded_file($ tmp,$ path);
$ sql =UPDATE info.profile SET Profile_pic ='。$移动。',pic_name ='。$ file。'WHERE Nick ='。$ _ SESSION ['Nick']。';
mysql_query($ sql)或者死(Error:.mysql_error());
$ _SESSION ['pic'] = $ path;
echo图片添加成功:) :) :);
}
我忽略了所有其他语句,因为它们不相关。以下是应该显示图像的示例。
< td rowspan = 2 align = center width = 100px> < img src =<?php $ _SESSION ['pic'];?>
alt =这是图片,如果它工作正常!!> < / TD>
当然,alt是一个小挑逗,但我已经尝试了一切,获取替代文字显示。有时会显示一个坏图片图标(例如,当您在允许图片显示之前在电子邮件中打开图片时)
当我回显路径时,它显示正确路径,就像我在手动输入时输入的内容一样。我在DB和会话中存储路径的原因是因为图像是配置文件图像,应该只显示该用户...不希望其他用户拥有其他用户图像作为他们的个人资料图=
相对于当前目录,路径应该是。你有没有检查过它?
试试在 Rohit
评论中给出的答案。
< img src ='<?php echo $ _SESSION ['pic']; >'/>
EDIT :: I found out that i am having a permission error. For whatever reason i dont have "permission" to grab the image from the images folder ... *
a few days ago i asked this question about uploading images and was very satisfied with the anwser. I integrated it into my site and it works no problem.
Image - Upload not responding, no access to $_FILES
The problem i am having now is i cannot retrieve the images in any way shape or form. I have tried opening them and setting them to read, with fopen($image, r). I tried even more complicated things like loading the image back into a database ... then it hit me that the anwser is simple.
I CAN see the image in my images folder, so should work no problem. But it doesnt =(
Here is the PHP script one more time,
if (isset($_FILES['fupload'] ))
{
$max_size = mysql_real_escape_string(strip_tags($_POST['MAX_FILE_SIZE']));
$file = $_FILES['fupload']['name'];
if(isset($max_size) && !empty($max_size) && !empty($file)) {
$file_type = $_FILES['fupload']['type'];
$tmp = $_FILES['fupload']['tmp_name'];
$file_size = $_FILES['fupload']['size'];
$allowed_type = array('image/png', 'image/jpg', 'image/jpeg', 'image/gif');
if(in_array($file_type, $allowed_type)) {
if($file_size < $max_size) {
$path ='images/'.$file;
$move = move_uploaded_file($tmp, $path);
$sql = "UPDATE info.profile SET Profile_pic='".$move."', pic_name='".$file."' WHERE Nick='".$_SESSION['Nick']."'";
mysql_query($sql) or die ("Error: " .mysql_error());
$_SESSION['pic'] = $path;
echo "image added successfully :) :) :) ";
}
I left out all the else statements, since they are not relevent. The folowing is an example of where the image should be displayed.
<td rowspan=2 align=center width=100px> <img src="<?php $_SESSION['pic']; ?>"
alt="Here would be the picture, if it was working !!"> </td>
The alt is a small teaser of course, but i have tried everything and with the current script i managed to get the alt text to display. Sometimes a "bad image" icon displayes (like when you open images in an email before allowing images to be displayed)
When i echo the path it shows the "right" path, just like i would enter when manualy giving it in. The reason i store the path in DB and in a session is because the image is a profile image and should only be displayed for THAT user ... wouldnt want other users having other images as their profile pic. =)
The path should be relative to the current directory
. Have u checked it ?
Try the answer given in comment by Rohit
.
<img src='<?php echo $_SESSION['pic']; ?>' />
这篇关于使用< img src ="">图片显示>不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!