HI, I have a simple PHP script, which takes a file reference from Flash and then resizes and uploads the image. The script works fine until I add any conditional statement, so this works:
<?php
//max width
$maxw=500;
//target directory
$dir="../images/";
//save path
$target = $dir . basename( $_FILES['Filedata']['name']) ;
//the uploaded file
$uploadedfile = $_FILES['Filedata']['tmp_name'];
//array image width and height
list($width,$height)=getimagesize($uploadedfile);
//test for width and height here
$newwidth=$maxw;
$newheight=($height/$width)*$newwidth;
//create a source image to manipulate
//Returns an image resource identifier on success, FALSE on errors.
$src = imagecreatefromjpeg($uploadedfile);
//create a color image
//Returns an image resource identifier on success, FALSE on errors.
$tmp=imagecreatetruecolor($newwidth,$newheight);
//boolean
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
//write the jpeg
if(imagejpeg($tmp,$target,100)) {
imagedestroy($src);
imagedestroy($tmp);
echo "The file has been uploaded";
}
?>
But this doesn’t, where I’ve inserted an if statement to test for a landscape image:
<?php
//max width
$maxw=500;
//target directory
$dir="../images/";
//save path
$target = $dir . basename( $_FILES['Filedata']['name']) ;
//the uploaded file
$uploadedfile = $_FILES['Filedata']['tmp_name'];
//array image width and height
list($width,$height)=getimagesize($uploadedfile);
//test for width and height here
$newwidth=$maxw;
$newheight=($height/$width)*$newwidth;
//any conditional prevents the upload from completing
if ($width > $height) {
}
//create a source image to manipulate
//Returns an image resource identifier on success, FALSE on errors.
$src = imagecreatefromjpeg($uploadedfile);
//create a color image
//Returns an image resource identifier on success, FALSE on errors.
$tmp=imagecreatetruecolor($newwidth,$newheight);
//boolean
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight, $width,$height);
//write the jpeg
if(imagejpeg($tmp,$target,100)) {
imagedestroy($src);
imagedestroy($tmp);
echo "The file has been uploaded";
}
?>