dongqie2028 2013-05-17 17:53
浏览 39
已采纳

在保存到服务器之前使用php从url调整图像大小[重复]

This question already has an answer here:

i'm trying to resize an image and save it to my server. i figured out how to save the image from a URL, but then I want to resize the image and save it in the exact same location. this is the script i'm currently using. it's saving the image but the resize isn't working.

$cover = $_POST['cover'];
$title = $_POST['title'];
$artist = $_POST['artist'];
$date = date('Y-m-d', strtotime($_POST['date']));


$url = $cover;
$save_name = $artist."_".$title.".jpg";
$save_name = str_replace(' ','',$save_name);
$save_directory = $_ENV["DOCUMENT_ROOT"]."/albums/images/art/";

if(is_writable($save_directory)) {
    file_put_contents($save_directory . $save_name, file_get_contents($url));
} else {
     exit("Failed to write to directory ".$save_directory);
}

$location = "http://www.MYURL.com/albums/images/art/".$save_name;
$sql = "INSERT INTO albums (artist, title, date, cover) VALUES ('".$artist."', '".$title."', '".$date."', '".$location."')";
mysql_query($sql);



include("resize-class.php");
$resizeObj = new resize($location);
$resizeObj -> resizeImage(150, 150, 'exact');
$resizeObj -> saveImage($save_name, 100);

i'm using resize-class.php which i thought would make things easy but it's not working. i think i might be confusing my resize path or output path but i'm not entirely sure. any tips would be really helpful

</div>
  • 写回答

1条回答 默认 最新

  • duankezong4064 2013-05-17 17:57
    关注

    I think it might be because you're trying to save the image to a URL, instead of a relative or absolute path on the server. If you look at your code, the location is set as an HTTP path.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器