droc60607 2014-05-01 17:35
浏览 50
已采纳

PHP MySQL imagejpeg()无效

I'm trying to save a thumbnail image onto my server using the below code...

// 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}");

All server permissions are fine! 0777!

Saves original image into 'Large Images' no problems.

  • 写回答

1条回答 默认 最新

  • dsebywql016137 2014-05-01 17:59
    关注

    Since you upload the large image to the parent folder you could do:

    if (!imagejpeg($new_image, '../' . $location_small, 100))
    {
        // Here you make sure this is the function that failed
        die('Imagejpeg failed');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maccms影视模板 制作影视网站失败 求
  • ¥15 stm32按键设置闹钟数进退位不正常
  • ¥15 三电平逆变器中点电位平衡问题
  • ¥20 这怎么写啊 java课设
  • ¥15 用C语言完成一个复杂的游戏
  • ¥15 如何批量更改很多个文件夹里的文件名中包含文件夹名?
  • ¥50 MTK手机模拟HID鼠标出现卡顿
  • ¥20 求下下面这个数据结构代码
  • ¥20 前端 二进制文件流图片转化异常
  • ¥15 github上的这个C语言项目如何跑起来