图片上传似乎正在运行,但最终结果文件是全黑区域。没有形象。
尺寸似乎正确,但新图片只是空白。
任何输入都非常感谢。这可能是我忽略的简单事情,我只需要第二眼。
/***** IMAGE UPLOAD VARIABLES *****/
// Destination
$main_dest = "../test_img/";
$thumb_dest = "../test_img/thumb/";
// Main Image Width
$new_img_width = "650";
// Thumb Image Width
$new_img_thumb_width = "100";
// Allowed Filesize (5mb)
$allowed_img_size = "5000000";
// Define Error Message
$error = "";
/***** EVENT EXISTING IMAGE INFO *****/
// Get image count
$get = "SELECT * FROM `tbl_event_imgs` WHERE `event_id` = '".$event_id."'";
$result = mysqli_query($database_link, $get);
$count = mysqli_num_rows($result);
// Main Setting
if ($count == 0) { $main = 1; } else { $main = 0; }
/***** IMAGE INFORMATION *****/
// Get image temporary name
$img_tmp = $_FILES['event_image']['tmp_name'];
// Get image name (original)
$img_name = basename($_FILES['event_image']['name']);
// Get image extension
$img_ext = pathinfo($img_name, PATHINFO_EXTENSION);
// Get image size
$img_size = $_FILES['event_image']['size'];
// Final image destination
$final_main_dest = $main_dest.$img_name;
/***** IMAGE VALIDATION *****/
// Validate Image Type (jpg, jpeg, gif, png)
if (($img_ext !== "jpg") && ($img_ext !== "jpeg") && ($img_ext !== "gif") && ($img_ext !== "png")) {
$upload_error = 1;
$error .= "filetype";
}
// Validate Image Size (5mb Allowed)
if ($img_size > $allowed_img_size) {
$upload_error = 1;
$error .= "filesize";
}
/**** BEGIN UPLOAD *****/
// Set src image (by ext)
if (($img_ext == "jpg" ) || ($img_ext == "jpeg")) {
$src_img = imagecreatefromjpeg($img_tmp);
} elseif ($img_ext == "png") {
$src_img = imagecreatefrompng($img_tmp);
} elseif ($img_ext == "gif") {
$src_img = imagecreatefromgif($img_tmp);
}
// Get src image height and width
$src_img_width = imagesx($src_img);
$src_img_height = imagesy($src_img);
// Set "desired" height
$new_img_height = floor($src_img_height * ($new_img_width / $src_img_width));
// Create Virtual Images
$virtual_main_img = imagecreatetruecolor($new_img_width, $new_img_height);
// Resize source image
imagecopyresampled($virtual_main_image, $src_img, 0, 0, 0, 0, $new_img_width, $new_img_height, $src_img_width, $src_img_height);
// Save final images
imagejpeg($virtual_main_img, $final_main_dest);
答案 0 :(得分:0)
结束很简单:
$ virtual_main_img是已定义的变量。
我无意中使用了" $ virtual_main_image"。
作品。