Search code examples
phpimageopencartfile-get-contentsfile-put-contents

Get Image With file_get_contents it return Not Found Error


I have one Image on another server (Image).but when i get this image With file_get_contents() function it will return

Not Found Error

and generate this Image.

file_put_contents(destination_path, file_get_contents(another_server_path));

plz help me. if there are another way to get those image.


Solution

  • Try this.

    There is problem with URL Special character.then you have to decode some special character from url basename.

    $imgfile = 'http://www.lagrolla.com.au/image/m fr 137 group.jpg';
    $destinationPath = '/path/to/folder/';
    $filename = basename($imgpath);
    $imgpath = str_replace($filename,'',$imgpath).rawurldecode($filename);
    copy($imgfile,$destination_path.$filename);