【问题标题】:PHP resize an image and upload to s3 not workingPHP调整图像大小并上传到s3不起作用
【发布时间】:2015-04-08 20:00:32
【问题描述】:

我想在亚马逊 s3 存储桶中上传我的图片。我的原始图片上传成功,但缩略图没有上传。

$name_pic = str_replace(' ', '_', trim($pic['name']));
$final_pic = time() . $name_pic;
$final_pic2 = $name_pic;

if (!defined('awsAccessKey')) define('awsAccessKey', 'AccessKey');
if (!defined('awsSecretKey')) define('awsSecretKey', 'SecretKey');

//instantiate the class
$s3 = new S3(awsAccessKey, awsSecretKey);

if ($s3->putObjectFile($pic['tmp_name'], "bucketname", $final_pic, S3::ACL_PUBLIC_READ)) {


    $new_width = 150;
    $new_height = 150;
    $image_p = imagecreatetruecolor($new_width, $new_height);
    $image = imagecreatefromstring(file_get_contents($fileTempName));
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, imagesx($image), imagesy($image));

    $s3->putObjectFile($pic['tmp_name'], "bucketname", $final_pic2, S3::ACL_PUBLIC_READ);

}

这里这一行上传原图

$s3->putObjectFile($pic['tmp_name'], "bucketname", $final_pic, S3::ACL_PUBLIC_READ)

而且这行应该是在resize后上传图片。但是不幸的是它也上传了原始图片。

$s3->putObjectFile($pic['tmp_name'], "bucketname", $final_pic2, S3::ACL_PUBLIC_READ);

【问题讨论】:

    标签: php image file-upload amazon-web-services amazon-s3


    【解决方案1】:

    我看不到,至少在您粘贴分配给 $final_pic2 的任何内容的代码中看不到。代码很混乱。 $pic['tmp_name'] 在哪里被操纵说有一个新图像?

    【讨论】:

      猜你喜欢
      • 2023-04-11
      • 2011-09-18
      • 2011-10-04
      • 1970-01-01
      • 2017-03-06
      • 2016-01-05
      • 2015-05-19
      • 2021-12-09
      • 2013-04-04
      相关资源
      最近更新 更多