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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵