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');
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号