PHP MySQL imagejpeg()无效

时间:2014-05-01 17:35:54

标签: php mysql

我尝试使用以下代码将缩略图图像保存到我的服务器上...

// Get Variables
$image = $_FILES['file']['tmp_name'];
$image_name = $_FILES['file']['name'];

$page = $_POST['page'];
$sub_category = $_POST['sub_category'];
$title = $_POST['title'];
$description = $_POST['description'];
$paypal = $_POST['paypal'];

// Resize Image
$image_size = getimagesize($image);
$image_width = $image_size[0];
$image_height = $image_size[1]; 

// Resizes image to roughly 150px by 100px
$new_size = ($image_width + $image_height)/($image_width * ($image_height / 65));

$new_width = $image_width * $new_size;
$new_height = $image_height * $new_size;

// Image locations on server
$location_large = "Product Images/Large Images/{$image_name}";
$location_small = "Product Images/Small Images/{$image_name}";

// Create New Image 
$new_image = imagecreatetruecolor($new_width, $new_height);

$source_image = imagecreatefromjpeg($image);    

imagecopyresampled($new_image, $source_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);

imagejpeg($new_image, $location_small, 100);

// Upload original image    
move_uploaded_file($image, "../Product Images/Large Images/{$image_name}");

所有服务器权限都没问题! 0777!

将原始图像保存到'大图像'没问题。

1 个答案:

答案 0 :(得分:1)

由于您将大图像上传到父文件夹,您可以执行以下操作:

if (!imagejpeg($new_image, '../' . $location_small, 100))
{
    // Here you make sure this is the function that failed
    die('Imagejpeg failed');
}