【问题标题】:using php to resize images from url before saving to server [duplicate]在保存到服务器之前使用php从url调整图像大小[重复]
【发布时间】:2013-05-17 17:53:12
【问题描述】:

我正在尝试调整图像大小并将其保存到我的服务器。我想出了如何从 URL 保存图像,但后来我想调整图像大小并将其保存在完全相同的位置。这是我目前正在使用的脚本。它正在保存图像,但调整大小不起作用。

$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);

我正在使用resize-class.php,我认为这会让事情变得简单,但它不起作用。我想我可能会混淆我的调整大小路径或输出路径,但我不完全确定。任何提示都会很有帮助

【问题讨论】:

  • 好的,但是你使用save_name,它只有名字,你没有指出文件夹在哪里。 File.jpg(你用什么) /home/user/images/destiny/File.jpg 你应该用什么。检查文件是否没有保存在其他地方
  • 试试这个也检查gd是否安装if (extension_loaded('gd') && function_exists('gd_info')) { echo "<pre>"; var_dump(gd_info()); echo "</pre>"; }
  • ["GD 版本"]=> string(27) "捆绑(2.0.34 兼容)"

标签: php image resize


【解决方案1】:

我认为这可能是因为您试图将图像保存到 URL,而不是服务器上的相对或绝对路径。如果您查看您的代码,该位置被设置为 HTTP 路径。

【讨论】:

  • 我不知道?我该如何检查。我正在使用 bluehost
  • 以下是我发现的可以帮助您检查的内容:bluehostforum.com/…
  • 这应该是评论,它没有回答问题。
  • 任何时候你必须向 OP 提出问题,这不是答案。
  • 我删除了问题部分。话虽如此,我确实在下面直接提供了答案。不需要蛇精。
猜你喜欢
  • 1970-01-01
  • 2013-08-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-17
  • 2012-12-14
  • 2011-09-01
  • 1970-01-01
相关资源
最近更新 更多