Priya
Priya

Reputation: 165

file_get_contens from remote url not working

i am trying to copy remote image file and reducing the size of image file and uploading to server but image file is created but it is not working .it gives error that image can not be displayed as it contains errors.

my code is this

<?php 

$url = 'http://www.indiancinemagallery.com/gallery/vaani-kapoor/Vaani-Kapoor-at-Radio-Mirchi-Stills-(9)9678.jpg';
$img = '/home/xxxxxxx/public_html/xyyyyyy/test.jpg';
$im = imagecreatefromjpeg($url);
$fimg=imagejpeg($im, NULL, 60);

file_put_contents($img, file_get_contents($fimg));

?>

Upvotes: 0

Views: 98

Answers (3)

H&#252;seyin BABAL
H&#252;seyin BABAL

Reputation: 15550

You need to read it from file by getting content, write it to file and read from file like;

<?php 

$url = 'http://www.indiancinemagallery.com/gallery/vaani-kapoor/Vaani-Kapoor-at-Radio-Mirchi-Stills-(9)9678.jpg';
$img = '/home/xxxxxxx/public_html/xyyyyyy/test.jpg';
file_put_contents($img, file_get_contents($url));
$im = imagecreatefromjpeg($img);
$fimg=imagejpeg($im, NULL, 60);


?>

Upvotes: 1

Musa
Musa

Reputation: 97672

Why are you trying to save the image twice.
Your first try is incorrect, it should be

imagejpeg($im, $img, 60); 

and don't do the file_put_contents

Upvotes: 1

xdazz
xdazz

Reputation: 160863

file_get_contents take a string as the parameter. imagejpeg just output image to browser or file, and return a boolean.

$url = 'http://www.indiancinemagallery.com/gallery/vaani-kapoor/Vaani-Kapoor-at-Radio-Mirchi-Stills-(9)9678.jpg';
$img = '/home/xxxxxxx/public_html/xyyyyyy/test.jpg';
file_put_contents($img, file_get_contents($url));

Upvotes: 0

Related Questions