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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?