Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

img src

Posted on 2014-12-01
10
Medium Priority
?
76 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 84

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 84

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 84

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 84

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

927 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