ye, but i always go th the manual before i use the forum. And i use the forum for a little more dynamic help than the static help the manual offers..
I rewrote the whole thing, but cant test it.. server does not allow imagejpeg() to open file for writing..
is this gonna work?
function createThumbnailOnFTP($fileSrc, $thumb_width = 160, $thumb_height = 80, $ftp_server, $ftp_user, $ftp_pass, $ftp_destdir = 0, $name) {
// Determining file extention
$ext = strtolower( substr($fileSrc, strrpos($fileSrc, ".")) );
if($ext == ".png") {
$base_img = ImageCreateFromPNG($fileSrc);
} else if(($ext == ".jpeg") || ($ext == ".jpg")) {
$base_img = ImageCreateFromJPEG($fileSrc);
} else if($ext == ".gif") {
$base_img = ImageCreateFromGIF($fileSrc);
}
// If the image is broken, skip it?
if (!$base_img) {
return false;
exit;
}
// Get image sizes from the image object we just created
$img_width = imagesx($base_img);
$img_height = imagesy($base_img);
// Working out thumb height
//$ratio = $img_height / $img_width;
//$thumb_height = $thmb_width * $ratio;
$thumb_img = ImageCreateTrueColor($thumb_width, $thumb_height);
ImageCopyResampled($thumb_img, $base_img, 0, 0, 0, 0, $thumb_width, $thumb_height, $img_width, $img_height);
if( $ext == ".png" ) {
ImagePNG($thumb_img, $name.$ext);
} else if (($ext == ".jpeg") || ($ext == ".jpg")) {
ImageJPEG($thumb_img, $name.$ext);
} else if ($ext == ".gif") {
ImageGIF($thumb_img, $name.$ext);
}
$fp = fopen($name.$ext, 'r');
//Connect to ftp server
$ftp = ftp_connect($ftp_server);
if (!$ftp) {
echo("Error connecting to ".$ftp_server.".");
return false;
}
//Login to ftp server
$ftp_login = ftp_login($ftp, $ftp_user, $ftp_pass);
if (!$ftp_login) {
echo("Error logging into ".$ftp_server.".");
return false;
}
//Change directory
if($ftp_destdir != 0) {
$dir = ftp_chdir($ftp, $ftp_destdir);
if (!$dir) {
echo("Couldn't change directory");
return false;
}
}
$put = ftp_fput($ftp, $name.$ext, $fp, FTP_BINARY);
if (!$put) {
echo("Error saving file to FTP");
return false;
}
fclose($fp);
// Clean up our images
unlink($thumb_img.$ext);
ImageDestroy($base_img);
ImageDestroy($thumb_img);
return true;
}