Hi, What i need doing is merging the 2 functions. The first is to FTP upload a file to a server and the second is resizing an image and renaming it. I need to get this to work so that the image is resized and then uploaded. I have tried but i cant get this to work and need it doing ASAP. If you can get this working i will give you $20. This is the function for ftp upload: php Code: function ftpupload($file, $img_tmp, $path){ $message = ''; if ($ftp = ftp_connect($_SESSION['ddomain'])) { if (ftp_login($ftp, $_SESSION['dname'], $_SESSION['dpass'])) { ftp_pasv($ftp, true); if (ftp_put($ftp, $path . $file, $img_tmp, FTP_BINARY)) { $message = "File uploaded"; } else { die("Could not upload file"); } } else { die("Could not login to FTP account"); } } else { die("Could not connect to FTP server"); } } PHP: This is the function image resize and rename: php Code: function uploadimage($value){ $file_type = $value['type']; $file_name = $value['name']; $file_size = $value['size']; $file_tmp = $value['tmp_name']; //check file extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[PHP_SELF]\">back</a>"; exit(); } //get the file extension. $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; //create a random file name $rand_name = md5(time()); $rand_name= rand(0,999999999); //get the new width variable. $ThumbWidth = 150; $ImgWidth = 450; //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list width and height and keep height ratio. list($width, $height) = getimagesize($file_tmp); $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; $newwidth2 = $ImgWidth; $newheight2 = $ImgWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; $newheight2 = $ImgWidth; $newwidth2 = $ImgWidth*$imgratio; } $resized_img = imagecreatetruecolor($newwidth, $newheight); $resized_img2 = imagecreatetruecolor($newwidth2, $newheight2); imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagecopyresized($resized_img2, $new_img, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height); //save image move_uploaded_file($resized_img, "uploads/thumbs/$rand_name.$file_ext"); move_uploaded_file($resized_img2, "uploads/big/$rand_name.$file_ext"); imagejpeg ($resized_img,"uploads/thumbs/$rand_name.$file_ext"); imagejpeg ($resized_img2,"uploads/big/$rand_name.$file_ext"); imagedestroy($resized_img); imagedestroy($resized_img2); imagedestroy($new_img); } $value = "$rand_name.$file_ext"; return $value; } PHP: Cheers, Adam
Try this to resize the image: <?php // This is the temporary file created by PHP $uploadedfile = $_FILES['uploadfile']['tmp_name']; // Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile); // Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile); // For our purposes, I have resized the image to be // 600 pixels wide, and maintain the original aspect // ratio. This prevents the image from being "stretched" // or "squashed". If you prefer some max width other than // 600, simply change the $newwidth variable $newwidth=600; $newheight=($height/$width)*600; $tmp=imagecreatetruecolor($newwidth,$newheight); // this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); // now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = "images/". $_FILES['uploadfile']['name']; imagejpeg($tmp,$filename,100); imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. ?> PHP:
I don't want to be using new functions to be honest as there is nothing wrong with the one's i have. I just need them combing.