Jump to content

Working scripts are not working now


Suchy

Recommended Posts

For 6 months I used the following codes to display photos on my site (it used a link from MySQL to a photo)

 

Few days ago my host upgraged the control pannel of my site to cpanel 11 from cpanel 9 (maybe something else but I do not know)

 

Now these scripts are not working (photos are not displayed)

 


<?php
header('Content-type: image/jpeg');

$link = $_GET['link'];
$x_max = $_GET['x_max'];

// function call
$photo_fun = open_photo (  $link );

// open photo
function open_photo ($temp_photo) {
        # JPEG:
        $im = @imagecreatefromjpeg($temp_photo);
        if ($im !== false) { return $im; }

        # GIF:
        $im = @imagecreatefromgif($temp_photo);
        if ($im !== false) { return $im; }

        # PNG:
        $im = @imagecreatefrompng($temp_photo);
        if ($im !== false) { return $im; }

        # GD:
        $im = @imagecreatefromgd($temp_photo);
        if ($im !== false) { return $im; }

        # GD2:
        $im = @imagecreatefromgd2($temp_photo);
        if ($im !== false) { return $im; }

        # WBMP:
        $im = @imagecreatefromwbmp($temp_photo);
        if ($im !== false) { return $im; }

        # XBM:
        $im = @imagecreatefromxbm($temp_photo);
        if ($im !== false) { return $im; }

        # XPM:
        $im = @imagecreatefromxpm($temp_photo);
        if ($im !== false) { return $im; }

        # ? 
        $im = @imagecreatefromstring(file_get_contents($temp_photo));
        if ($im !== false) { return $im; }

        return false;
}



// get size
$x = imagesx($photo_fun);
$y = imagesy($photo_fun);

$y_max = $y * ($x_max/$x);

// change size
$change_size = imagecreatetruecolor($x_max, $y_max);
imagecopyresampled($change_size, $photo_fun, 0, 0, 0, 0, $x_max, $y_max, $x, $y);

// text color
$white_color = imagecolorallocate($change_size, 255, 255, 255);

// add text to photo
imagestring($change_size, 3, 5, imagesy($change_size)-20, 'www.............com', $white_color);

imagejpeg($change_size) ;

?>

 


<?php
header('Content-type: image/jpeg');

$link = $_GET['link'];
$x_max = $_GET['x_max'];

// function call
$photo_fun = open_photo (  $link );

// open photo
function open_photo ($temp_photo) {
        # JPEG:
        $im = @imagecreatefromjpeg($temp_photo);
        if ($im !== false) { return $im; }

        # GIF:
        $im = @imagecreatefromgif($temp_photo);
        if ($im !== false) { return $im; }

        # PNG:
        $im = @imagecreatefrompng($temp_photo);
        if ($im !== false) { return $im; }

        # GD:
        $im = @imagecreatefromgd($temp_photo);
        if ($im !== false) { return $im; }

        # GD2:
        $im = @imagecreatefromgd2($temp_photo);
        if ($im !== false) { return $im; }

        # WBMP:
        $im = @imagecreatefromwbmp($temp_photo);
        if ($im !== false) { return $im; }

        # XBM:
        $im = @imagecreatefromxbm($temp_photo);
        if ($im !== false) { return $im; }

        # XPM:
        $im = @imagecreatefromxpm($temp_photo);
        if ($im !== false) { return $im; }

        # ? 
        $im = @imagecreatefromstring(file_get_contents($temp_photo));
        if ($im !== false) { return $im; }

        return false;
}



// get size
$x = imagesx($photo_fun);
$y = imagesy($photo_fun);

$y_max = $y * ($x_max/$x);

// change size
$change_size = imagecreatetruecolor($x_max, $y_max);
imagecopyresampled($change_size, $photo_fun, 0, 0, 0, 0, $x_max, $y_max, $x, $y);

imagejpeg($change_size) ;

?>

 

Both are simmilar, except the first one adds a watermark

 

 

So why are these scripts not functioning, and everything else is ?

Is there something I can do to fix this?

 

Here is the part of phpinfo form my site

 

screenshot003hh6.jpg

 

screenshot002xj1.jpg

 

 

Link to comment
https://forums.phpfreaks.com/topic/80843-working-scripts-are-not-working-now/
Share on other sites

Your calling your function before you even create it. Try changing your scripts to this

 

1st script

<?php
header('Content-type: image/jpeg');

$link = $_GET['link'];
$x_max = $_GET['x_max'];

// open photo
function open_photo ($temp_photo) {
        # JPEG:
        $im = @imagecreatefromjpeg($temp_photo);
        if ($im !== false) { return $im; }

        # GIF:
        $im = @imagecreatefromgif($temp_photo);
        if ($im !== false) { return $im; }

        # PNG:
        $im = @imagecreatefrompng($temp_photo);
        if ($im !== false) { return $im; }

        # GD:
        $im = @imagecreatefromgd($temp_photo);
        if ($im !== false) { return $im; }

        # GD2:
        $im = @imagecreatefromgd2($temp_photo);
        if ($im !== false) { return $im; }

        # WBMP:
        $im = @imagecreatefromwbmp($temp_photo);
        if ($im !== false) { return $im; }

        # XBM:
        $im = @imagecreatefromxbm($temp_photo);
        if ($im !== false) { return $im; }

        # XPM:
        $im = @imagecreatefromxpm($temp_photo);
        if ($im !== false) { return $im; }

        # ? 
        $im = @imagecreatefromstring(file_get_contents($temp_photo));
        if ($im !== false) { return $im; }

        return false;
}

// function call
$photo_fun = open_photo (  $link );

// get size
$x = imagesx($photo_fun);
$y = imagesy($photo_fun);

$y_max = $y * ($x_max/$x);

// change size
$change_size = imagecreatetruecolor($x_max, $y_max);
imagecopyresampled($change_size, $photo_fun, 0, 0, 0, 0, $x_max, $y_max, $x, $y);

// text color
$white_color = imagecolorallocate($change_size, 255, 255, 255);

// add text to photo
imagestring($change_size, 3, 5, imagesy($change_size)-20, 'www.............com', $white_color);

imagejpeg($change_size) ;

?>

 

2nd script


<?php
header('Content-type: image/jpeg');

$link = $_GET['link'];
$x_max = $_GET['x_max'];

// open photo
function open_photo ($temp_photo) {
        # JPEG:
        $im = @imagecreatefromjpeg($temp_photo);
        if ($im !== false) { return $im; }

        # GIF:
        $im = @imagecreatefromgif($temp_photo);
        if ($im !== false) { return $im; }

        # PNG:
        $im = @imagecreatefrompng($temp_photo);
        if ($im !== false) { return $im; }

        # GD:
        $im = @imagecreatefromgd($temp_photo);
        if ($im !== false) { return $im; }

        # GD2:
        $im = @imagecreatefromgd2($temp_photo);
        if ($im !== false) { return $im; }

        # WBMP:
        $im = @imagecreatefromwbmp($temp_photo);
        if ($im !== false) { return $im; }

        # XBM:
        $im = @imagecreatefromxbm($temp_photo);
        if ($im !== false) { return $im; }

        # XPM:
        $im = @imagecreatefromxpm($temp_photo);
        if ($im !== false) { return $im; }

        # ? 
        $im = @imagecreatefromstring(file_get_contents($temp_photo));
        if ($im !== false) { return $im; }

        return false;
}

// function call
$photo_fun = open_photo (  $link );

// get size
$x = imagesx($photo_fun);
$y = imagesy($photo_fun);

$y_max = $y * ($x_max/$x);

// change size
$change_size = imagecreatetruecolor($x_max, $y_max);
imagecopyresampled($change_size, $photo_fun, 0, 0, 0, 0, $x_max, $y_max, $x, $y);

imagejpeg($change_size) ;

?>

 

Because PHP is a parsed/interpreted language, function definitions can occur in the code any place.

 

I recommend checking your web server log for errors.

 

Is nothing displayed, not even the red-x where the photo should be? What do you get in your browser's "view source" of the page the images are on?

 

Post the code with the <img src="...." tag that is using the two php files you posted.

Yeah that red X shows up, as if the photos were not on the server (they are)

 

dirrect link to a photo is:

http://www.......org/fotki_mini/89544795.jpg

 

 

 

the link that the scripts use are: (I right clicked on the red x and copied the link)

(first script)

http://www.........org/funkcje/pokaz_fotke.php

 

(second script)

http://www.......org/funkcje/pokaz_fotki.php?link=http://www.........org/fotki_mini/89544795.jpg&x_max=240

 

img tags form page source:

(first script)

<img src="funkcje/pokaz_fotke.php" alt="........org" border = "0"> </img>

 

(second script)

<img alt="........org" border = "0" src="funkcje/pokaz_fotki.php?link=http://www.......org/fotki_mini/219166845.jpg&x_max=240"> </img>

 

PS. these names are in polish

I modified the function little bit to see the errors:

 

...
function open_photo ($temp_photo) {
        # JPEG:
        $im = imagecreatefromjpeg($temp_photo);
        if ($im !== false) { return $im; } else { die ('Unable to open image - JPEG'); }

        # GIF:
        $im = imagecreatefromgif($temp_photo);
        if ($im !== false) { return $im; } else { die ('Unable to open image - GIF'); }

        # PNG:
        $im = imagecreatefrompng($temp_photo);
        if ($im !== false) { return $im; } else { die ('Unable to open image - PNG'); }
...

 

Now when I run the script directly with its input:

 

I get 2 errors, as if my site was down:

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /home/______/public_html/_______/_______/pokaz_fotki.php on line 21

 

Warning: imagecreatefromjpeg(http://www._______/795.jpg) [function.imagecreatefromjpeg]: failed to open stream: Success in /home/_____/public_html/_____/______/pokaz_fotki.php on line 21

Unable to open image - JPEG

 

 

What is going on?

 

PS. I censored my url and key words since I don't want google caching them.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.