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.

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

报告相同问题?

悬赏问题

  • ¥15 MySQL创建时出现1064以下情况怎么办?
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重