Your attempt with file_get_contents
only works if php.ini
is set this way:
allow_url_fopen=true
But if it is enabled, nor does it need file_get_contents
, you can simplify with copy
:
copy( $urlOrigem, $arquivoDestino );
If you do not want or can not activate allow_url_fopen
, an alternative is 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 cURL
extension must be enabled.
About resizing image with PHP, we already have some answers on the site .