Solved

img src

Posted on 2014-12-01
10
69 Views
Last Modified: 2015-01-08
Im trying to put in an image source as:-
<img src="../logos/getImgLogo.php?logoID=<?php echo $row['cid']; ?>" alt="Logo" />

Open in new window


However inside html doesnt display the image, instead just displays the image as if it doesnt exist, however if I goto the location where getImgLogo.php exists and load it works fine.

Im assuming the issue is that src doesnt know its a png file so cant display it. Is this correct and if so how can I tell it there is a PNG coming in like:-
<img src="data:image/png;../logos/getImgLogo.php?logoID=<?php echo $row['cid']; ?>" alt="Logo" />

Open in new window


or is there another issue?

Thank you
0
Comment
Question by:tonelm54
10 Comments
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40473952
You could try this:

<?php $img = "../logos/getImgLogo.php?logoID=$row['cid']; ?>
<img src="<?php echo $img ?>" alt="Logo" />

Open in new window


Cheers
0
 
LVL 9

Expert Comment

by:Brian Tao
ID: 40474133
The problem is in your getImgLogo.php and not in your img tag.  Please post the php code so that people can help.
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40474213
The PHP page must return the correct MIME type in a header for the image type to be recognized.  It also must be sent first before the image content.
header('Content-type: image/png'); 

Open in new window

Look at the first example on this page: http://php.net/manual/en/function.imagecreate.php
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:tonelm54
ID: 40485510
Im trying to show the image as:-
<HTML>
<HEAD>
</HEAD>
<BODY>
<img src="showImage.php?logoID=3" />
</BODY>
</HTML>

Open in new window


And the to get the image (simplified code):-
<?php
    if (file_exists($_GET['logoID'] . ".dat")) {
        $filename = $_GET['logoID'] . ".dat";
    } else {
        $filename = "noLogo.dat";
    }
    
    $savename = $_GET['logoID'] . ".png";
    
    header("Content-Type: image/png");
    header("Content-Length: " . filesize($filename));    
    //header("Content-Disposition: attachment; filename=". $row['name']);    
    
    list($width, $height) = getimagesize($filename);
    $newwidth = 50;
    $newheight = 30;
    
    $imgsrc = file_get_contents($filename);
    
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    
    $source = imagecreatefrompng($filename);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    
    imagepng($thumb);
    
    imagedestroy($thumb);
    imagedestroy($source);
?>

Open in new window


Ive attached the code, in the hope someone can help, please

Thank you
index.php
showImage.php
2.png
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40485649
Works perfectly when you change "logoID=3" to "logoID=2" so it looks for the right image.
0
 

Author Comment

by:tonelm54
ID: 40485698
Sorry, uploaded a some wrong test data.

Im a bit confused, as when I upload it to a testing server I get the image load then disapear in chrome???

For example:-
http://test.uwh.tonycross.me.uk/imgSrc/index.php

But image loads fine:-
http://test.uwh.tonycross.me.uk/imgSrc/showImage.php?logoID=2

Very confused now :-S
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 40485774
No, your test site works just fine from here in Chrome and Firefox.
0
 

Accepted Solution

by:
tonelm54 earned 0 total points
ID: 40494746
I actually found the issue and now it works with all browsers.

The issue was with the line:-
header("Content-Length: " . filesize($filename));  

Open in new window


When I removed it, it works fine. I dont understand why though, or why it works on your browsers and not mine
0
 
LVL 83

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 500 total points
ID: 40494780
Very puzzling because that is not done in the browser but on the server.
0
 

Author Closing Comment

by:tonelm54
ID: 40537504
Found the problem myself, but thank you for your assistance
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question