Download image in link with PHP parentheses

0

So I'm trying to download an image through a url ... I already identified the problem example:

    <?php
$imgurl = 'http://ia.media-imdb.com/images/M/MV5BNTA2MTk3NzI5Ml5BMl5BanBnXkFtZTgwNzU2MzYyNzE@._V1_SX300.jpg';
if( !@copy( $imgurl, './teste.jpg' ) ) {
    $errors= error_get_last();
    echo "COPY ERROR: ".$errors['type'];
    echo "<br />\n".$errors['message'];
} else {
    echo "File copied from remote!";
}

this works ... now if I try with this url: link (1) .jpg of the link error ...

    
asked by anonymous 16.02.2017 / 17:01

1 answer

5

The problem is the space in the name of the photo. To resolve, you can use rawurlencode() in the part of the name.

copy('http://fatisa.com.br/imoveis/docs/imoveis/'.rawurlencode('terreno (1).jpg'), './teste.jpg');

I ran the command and saved the photo without any problem.

    
16.02.2017 / 17:11