Help - Search - Members - Calendar
Full Version: Problem with scripted images
Invision Power Services > Community Forums > Community Web Design and Coding
Sebastian Mares
Hello!

I have a problem with a dynamic image not showing up when uploaded to my remote server. This is the script:

CODE

<?php

// Header-Informationen einstellen
Header ('Content-type: image/png');
Header ('Cache-Control: must-revalidate, no-cache, no-store, post-check=0, pre-check=0');
Header ('Pragma: no-cache');

// Bildgre einstellen
$img_width = 521;
$img_height = 50;

// Bild erstellen
$image = imagecreate($img_width, $img_height);

// Farben einstellen
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$red = imagecolorallocate($image, 255, 0, 0);
$grey = imagecolorallocate($image, 204, 204, 204);
$green = imagecolorallocate($image, 128, 220, 0);

// Hintergrund-Farbe und Rnder einstellen
imagefilledrectangle($image, 0, 0, $img_width, $img_height, $white);
imageline($image, 0, 0, 0, $img_height, $black); // Rand links
imageline($image, 0, 0, $img_width, 0, $black); // Rand oben
imageline($image, 0, $img_height - 1, $img_width, $img_height - 1, $black); // Rand unten
imageline($image, $img_width - 1, 0, $img_width - 1, $img_height - 1, $black); // Rand rechts

// Liedinformationen aus Textdatei extrahieren
$song_info = file("http://maresweb.homeip.net/foobar2000.txt");
// Schriftart einstellen
$font = 'cour.ttf';

// Text und Fortschrittsanzeige drucken
if(empty($song_info[0])) {
ImageTTFText ($image, 9, 0, 10, 19, $black, $font, 'Ich hre gerade keine Musik.');
imagefilledrectangle($image, 10, 30, 10, 40, $grey);
}
else {
ImageTTFText ($image, 9, 0, 10, 19, $black, $font, $song_info[0]);
imagefilledrectangle($image, 10, 30, $song_info[1] + 10, 40, $grey);
}
imageline($image, 10, 30, 10, 40, $black); // Rand links
imageline($image, 10, 30, 510, 30, $black); // Rand oben
imageline($image, 10, 40, 510, 40, $black); // Rand unten
imageline($image, 510, 30, 510, 40, $black); // Rand rechts

// Bild ausgeben und Speicher befreien
imagepng($image);
imagedestroy($image);

?>


The .htaccess file looks like this:

CODE
<Files playing.png>
 ForceType application/x-httpd-php
</Files>


When the image is placed on my local server, everything works fine, but when calling it from the remote server, I get "The image "http://school.maresweb.de/playing.png" cannot be displayed, because it contains errors.". Any idea what might be causing this? IE displays the following:

QUOTE
Warning: file(http://maresweb.homeip.net/foobar2000.txt) [function.file]: failed to open stream: HTTP request failed! HTTP/1.1 304 Not Modified in /www/htdocs/sebmar/playing.png on line 30
PNG  IHDR 2$nU$PLTÈ???___v9xIDATx1o1Աo8}xdx墨 R1$m]wT( Jb?a# Xb Xb @—NxmGm9dZ ɨ@PM!ytql kz:L:LߖDjsHzw5Tf"&t 2`r-KW8SQe|KA`ap􋦎.*{d| OWδEsRn7xgi{X0x6Mbk se殤.1 , -OjTo-Ng/, nx/d55]c/ ַ4"*Il,j_߈YN#Co4(P)Rϊ33Lcj}wbTg5Zh
k})}wgG _B"'h Xb XbZq<z! @, @,B Op-s @, @,؇wrS;hnIENDB`
Sebastian Mares
OK, the problem is that it doesn't like this line:

CODE
$song_info = file("http://maresweb.homeip.net/foobar2000.txt");


How else can I fetch data from a remote server? tongue.gif
_
Uh... sockets? O.O

You could just connect and GET /foobar2000.txt HTTP/1.1...
Chad
Thatas because it is just grabbing the file and not reading its contents...

CODE
$song_info = @implode( "" ,  @file("http://maresweb.homeip.net/foobar2000.txt") );


I'm not sure if there are any advantages over using implode() or actually opening and reading the file.

The @ operator will surpress any errors if they are present.
For testing, remove them to make sure there are not any errors. Then put them there so errors won't throw off sites if they decide to show up. wink.gif

Chad
Sebastian Mares
QUOTE(Chad @ Mar 20 2005, 08:20 PM)
Thatas because it is just grabbing the file and not reading its contents...

CODE
$song_info = @implode( "" ,  @file("http://maresweb.homeip.net/foobar2000.txt") );


I'm not sure if there are any advantages over using implode() or actually opening and reading the file.

The @ operator will surpress any errors if they are present.
For testing, remove them to make sure there are not any errors.  Then put them there so errors won't throw off sites if they decide to show up. wink.gif

Chad
*


Nope, doesn't work. I guess it doesn't like reading remote files, since reading a local file (if I copy foobar2000.txt to the server and change the path respectively) works.
Chad
Hmm... thats wierd. I do it all the time. tongue.gif
The homeip.net... Is that like a no-ip.com thing?

Chad
Sebastian Mares
QUOTE(Chad @ Mar 20 2005, 08:47 PM)
Hmm... thats wierd.  I do it all the time. tongue.gif
The homeip.net... Is that like a no-ip.com thing?

Chad
*


Yep, it's my local machine. The thing is that the file is updated every second on play and therefore I cannot upload the file to the remote server (or my hosting provider will think I am doing a DoS attack).
Chad
You can sleep the script. I have no idea how to go about that though. Never done it.
The remote linking issue can be a firewall problem. Are you on a firewall?

Chad
Sebastian Mares
QUOTE(Chad @ Mar 20 2005, 08:51 PM)
You can sleep the script.  I have no idea how to go about that though.  Never done it.
The remote linking issue can be a firewall problem.  Are you on a firewall?

Chad
*


Yes, but the firewall isn't blocking access to ports 80 and 21 since everyone can access them. original.gif

You can try for yourself: http://maresweb.homeip.net
Sebastian Mares
Crap, fopen() doesn't work either. I always get the message

QUOTE
... failed to open stream: HTTP request failed! HTTP/1.1 304 Not Modified in /www/htdocs/sebmar/playing.png on line 30
_
Why not try sockets? unsure.gif
Chad
Well, the only thing I can think is that your host won't allow it.
I can understand why, but it is a pain in the butt.

I would suggest contacting your host to see if they allow you to remote link from their servers to your localhost.

Chad
Rikki
To open a remote file using file, fopen etc. PHP needs to use the correct wrapper and have the permission to do so.

More info on wrappers at http://uk2.php.net/manual/en/wrappers.php. I don't know off-hand what settings you may need to configure so have a look through the PHP site.

[edit] Check allow_url_fopen is enabled in php.ini.
Sebastian Mares
QUOTE(Rikki @ Mar 21 2005, 01:12 AM)
To open a remote file using file, fopen etc. PHP needs to use the correct wrapper and have the permission to do so.

More info on wrappers at http://uk2.php.net/manual/en/wrappers.php. I don't know off-hand what settings you may need to configure so have a look through the PHP site.

[edit] Check allow_url_fopen is enabled in php.ini.
*


Weird, it works now after removing the .htaccess file from my local server. It had the same data as the remote one:

CODE
<Files playing.png>
 ForceType application/x-httpd-php
</Files>

ErrorDocument 404 http://school.maresweb.de/404.php

Options -Indexes


blink.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.