这是您每天上传并裁剪“简介”图片脚本/函数。有人浏览他们的电脑并上传图片。这个图像然后被上传到一个单独的服务器。在此之后,同样的图像被提出来让他们“裁剪”,然后保存该新版本并移除旧的大图像。我有这一切运作良好,除了一个小细节...ftp_put():在将图像添加到单独的服务器时,它也将其添加到本地服务器
一旦他们保存裁剪版本,它也保存到主目录中的本地服务器。我无法弄清楚为什么它会这样做,因为它专门设置为仅上传到另一个。
这里是信息:
$upload_dir = "profile_images/". $username; // The directory for the images to be saved in
$upload_path = $upload_dir."/"; // The path to where the image will be saved
$large_image_name = "resized_pic.jpg"; // New name of the large image
$thumb_image_name = $userid ."00". $i .".jpg"; // New name of the thumbnail image
$max_file = "200000"; // Approx 200kb
$max_width = "500"; // Max width allowed for the large image
$thumb_width = "80"; // Width of thumbnail image
$thumb_height = "80"; // Height of thumbnail image
//Image Locations
$large_image_location = $upload_path.$large_image_name;
$thumb_image_location = $upload_path.$thumb_image_name;
这里是调整裁剪图像的功能:
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
global $ftp_server;
global $ftp_user_name;
global $ftp_user_pass;
global $thumb_image_location;
global $large_image_location;
global $user;
global $userid;
global $username;
global $success;
global $error;
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
ftp_pasv($conn_id, true);
if ($login_result) {
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
$source = imagecreatefromjpeg($image);
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
imagejpeg($newImage,$thumb_image_name,90);
// chmod($thumb_image_name, 0777);
$upload = ftp_put($conn_id, $thumb_image_location, $thumb_image_name, FTP_BINARY);// upload the file
ftp_chmod($conn_id, 0777, $thumb_image_location);
if ($upload) {
// User DB Queries
$time = strtotime("now");
$time = $time + 3600;
$date = date(c, $time);
$path = 'http://www.otherserver.net/'. $thumb_image_location;
$fileQuery = "INSERT INTO `avatars`(userid, username, path, date) VALUES('$userid', '$username', '$path', '$date')";
$fileResult = mysql_query($fileQuery);
$userQuery = "UPDATE `users` SET avatar = '$path' WHERE username = '$user'";
$userResult = mysql_query($userQuery);
if ($fileResult && $userResult) {
$success = 'Your avatar has been uploaded successfully.';
} else {
$error = 'Something went wrong with your upload.';
}
}
}
ftp_close($conn_id); // close the FTP stream
}
最后,这里是当函数被调用:
if (isset($_POST["upload_thumbnail"]) && strlen($large_photo_exists) > 0) {
//Get the new coordinates to crop the image.
$x1 = $_POST["x1"];
$y1 = $_POST["y1"];
$x2 = $_POST["x2"];
$y2 = $_POST["y2"];
$w = $_POST["w"];
$h = $_POST["h"];
//Scale the image to the thumb_width set above
$scale = $thumb_width/$w;
resizeThumbnailImage($thumb_image_name, "http://otherserver.net/". $large_image_location,$w,$h,$x1,$y1,$scale);
}
再次,一切工作正常,除了它保存最终(裁剪)的图像到本地服务器以及(是的,我t也将它保存到另一台服务器上,这样一部分就可以了)。
全部固定。我只是不得不“解除”上传到本地服务器的图像。 – Nate 2011-06-07 05:20:07