my hosting provider doesn't offer the GD library therefore I use a external server to change the image.
i'll upload an image to image.php on the 'local' server
image.php
<?php
//start session
session_start();
//include external files
require_once("inc.php");
$max_filesize = 100000;
//-----------------------------------------------
//checks if the image is valid
function validImage($image){
global $errorH,$max_filesize;
if (!is_array($image) || !$image['name']) {
return false;
}
if($max_filesize && ($image["size"] > $max_filesize)) {
return false;
}
if (!isset($image['tmp_name']))
{
return false;
}
return true;
}
//-------------------------------------
if(authOk())
{
if(validImage($_FILES['image']))
{
$image = $_FILES['image'];
$large_max_width = 502;
$large_max_height = 140;
$small_max_width = 180;
$small_max_height = 71;
$imagename = "../tmp/".time().".jpg";
//save a temp file
move_uploaded_file($image['tmp_name'], $imagename);
//create a filename
$filename = "belt_".$aid."jpg";
//load the small image
$fp = fopen("http://***/change_image.php?
filename=$imagename&width=$small_max_width&height=$small_max_height
&max_filesize=$max_filesize", "rb");
while(!feof($fp))
{
$cont.= fread($fp,1024);
}
fclose($fp);
$small_file_name = "/../oos/images/articles/".$filename;
$fp2 = fopen($small_file_name,"w");
fwrite($fp2,$cont);
fclose($fp2);
echo "afbeelding: <BR><img src='$small_file_name'>";
//load the large image
//save the image
//delete tmp file
//save link in the database
//redirect to the article list
}
//header("Location: index.php?pid=images&aid=$aid");
//exit;
}
else
{
header("Location: index.php");
exit;
}
?>
this script temporarily saves the image.
Next an external script image_change.php is opened using fopen()
image_change.php
<?php
$fp = fopen("http://www.***.com/test/admin/".$filename, "r");
$imageFile = fread ($fp, 3000000);
fclose($fp);
$tmpfname = tempnam ("tmp/", "IMG");
$fp = fopen($tmpfname, "w");
fwrite($fp, $imageFile);
fclose($fp);
$src_img = imagecreatefromjpeg($tmpfname);
$src_width = imagesx($src_img); // width original image
$src_height = imagesy($src_img); // height original image
$src_div = $src_width / $src_height;
$dst_div = $width / $height;
if($src_div >= $dst_div)
{
$dst_width = $width;
$dst_height = $src_height * ($width / $src_width);
}
else
{
$dst_width = $src_width * ($height / $src_height);
$dst_height = $height;
}
$dst_img = imagecreatetruecolor($dst_width,$dst_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
unlink($tmpfname);
if (!$dst_img) {
return false;
}
Header( "Content-Type: image/jpeg");
imagejpeg($dst_img, '', 100);
?>
change_image.php is being executed well. I have tested it with the url from the fopen() in line 55.
But the script doesn't work something goes wrong in line 55 I guess.
But i don't get a error message. When i execute the script in internet explorer i get a 'cannot find server' message.
How can is solve this problem. When i remove the lines 55 up to 61 the script is executed correctly. But offcourse nothing happens.