-1

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

patricko
  • 831
  • 4
  • 16
  • 34
  • ok, but you use the save_name, it only have the name, you dont point where is the folder. File.jpg (what you use) /home/user/images/destiny/File.jpg What you should use. Check if the file is not saved in another place – Lefsler May 17 '13 at 17:58
  • Try this too check if `gd` is installed `if (extension_loaded('gd') && function_exists('gd_info')) { echo "
    "; var_dump(gd_info()); echo "
    "; }`
    – The Alpha May 17 '13 at 18:04
  • ["GD Version"]=> string(27) "bundled (2.0.34 compatible)" – patricko May 17 '13 at 18:05

1 Answers1

1

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.

probablyup
  • 7,636
  • 1
  • 27
  • 40