His attempt with file_get_contents
only works if the php.ini
is set this way:
allow_url_fopen=true
But if you’re qualified, you don’t even need file_get_contents
, can already simplify with copy
:
copy( $urlOrigem, $arquivoDestino );
If you do not wish or cannot activate allow_url_fopen
, an alternative is the cURL
:
$curl = curl_init( $urlOrigin );
$file = fopen( $fileDestination, 'wb' );
curl_setopt( $curl, CURLOPT_FILE, $file );
curl_setopt( $curl, CURLOPT_HEADER, 0 );
curl_exec( $curl );
curl_close( $curl );
fclose( $file );
In this second case, the extension cURL
has to be enabled.
About resizing image with PHP, we already have some answers on the site.