0

I been trying to create a simple php script to covert a dynamic url generated by another php into an image but all i get is a blank page, does anybody know why this is not working?

<?php
include('icecast.php');
$cover = ($stream['artist']['top_albums']['0']['image']['3']);
header('Content-Type: image/jpeg');
readfile('$cover');
?>

I have try so many different ways but i still get the same result.

rijotech
  • 356
  • 3
  • 17
  • 2
    Please paste the complete code.. – geekman Dec 25 '12 at 18:59
  • In the answers below you are saying "The output only shows a lot of symbols and letters" - how are you putting the image on a page? - is this an HTTP call or ajax? This is why we ask for more code. Ambiguity doesn't help resolve problems. – Popnoodles Dec 25 '12 at 20:27
  • i Already added a link to the projects page I'm not being ambiguity! – rijotech Dec 25 '12 at 20:39

3 Answers3

2

Well, at least you are trying to use not variable $cover but literal string '$cover'.

It is strings have to be delimited by quotes, but variables should be accessed without them.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
1

this worked for me:

The important points is that you must send a Content-Type header. Also, >you must be careful not include any extra white space (like newlines) in >your file before or after the tags.

As suggested in the comments, you can avoid the danger of extra white >space at the end of your script by omitting the ?> tag:

taken from this answer

Community
  • 1
  • 1
0

You are using '$cover' when it should be just $cover

readfile($cover);

Also make sure $cover has complete file name, with the extension, and add

header('Content-Length: ' . filesize($cover));

Also do this:

header('Content-Type:image/jpeg');
header('Content-Length: ' . filesize($cover));
readfile($cover);

Use both headers, alo verify if your file has jpeg type.... And make sure no output till headers, absolutely none. No echo. And as content type is image, there should be no output other than the file at all!!!

geekman
  • 2,224
  • 13
  • 17
  • Your provided solution kind works the only problem now is the image is not displaying the way it should be, the image is being displaying as symbols and letters. – rijotech Dec 25 '12 at 19:19
  • I don't want to disclose the file codes since is not my creation but i can write a link to it so you can see what is going on on icecast.php [link]https://code.google.com/p/icecast-now-playing-script/source/browse/trunk/icecast.php[/link] – rijotech Dec 25 '12 at 19:36
  • remove all headers... use echo $cover...and see what is happening. If yoy are getting path properly or not – geekman Dec 25 '12 at 19:40
  • the output is the url to the image – rijotech Dec 25 '12 at 19:47