Download image link with PHP parentheses

Asked

Viewed 1,554 times

0

so I’m trying to download an image through a url... I’ve 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: http://www.fatisa.com.br/imoveis/docs/imoveis/terreno (1). jpg link error...

  • the url you are testing is exactly this including the space ?

  • This...I’ve tried to replace spaces and parentheses but it won’t...

  • As such, replaced by what ?

1 answer

5

The problem is the space in the name of the photo. To solve you can use a rawurlencode() on 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 problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.