Если у вас есть простая функция скручивания, которую вы можете использовать повторно, загрузка этого файла довольно проста. Вам нужно будет загрузить копию cacert.pem
- , которую вы можете найти здесь - сохранить на своем веб-сервере и отредактировать путь, указанный ниже, для соответствия.
function curl( $url, $options=array(), $headers=array() ){
# EDIT this to suit...
$cacert='c:/wwwroot/cacert.pem';
$curl=curl_init();
if( parse_url( $url,PHP_URL_SCHEME )=='https' ){
curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, 2 );
curl_setopt( $curl, CURLOPT_CAINFO, $cacert );
}
curl_setopt( $curl, CURLOPT_URL,trim( $url ) );
curl_setopt( $curl, CURLOPT_AUTOREFERER, true );
curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $curl, CURLOPT_FAILONERROR, true );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLINFO_HEADER_OUT, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_BINARYTRANSFER, true );
curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 20 );
curl_setopt( $curl, CURLOPT_TIMEOUT, 60 );
curl_setopt( $curl, CURLOPT_USERAGENT, 'Mozilla/5.0' );
curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 );
curl_setopt( $curl, CURLOPT_ENCODING, '' );
if( isset( $options ) && is_array( $options ) ){
foreach( $options as $param => $value ) curl_setopt( $curl, $param, $value );
}
if( $headers && is_array( $headers ) ){
curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
}
$res=(object)array(
'response' => curl_exec( $curl ),
'info' => (object)curl_getinfo( $curl ),
'errors' => curl_error( $curl )
);
curl_close( $curl );
return $res;
}
/* Create the name and path for the saved file */
$saveto='c:/temp/1007ci2.xlsx';
/* begin writing to a stream */
$fp=fopen( $saveto, 'w' );
/* fetch this url */
$url='https://www.esri.cao.go.jp/jp/stat/di/1007ci2.xlsx';
/* indicate we wish to download a file and save it to the stream already created */
$options=array(
CURLOPT_FILE => $fp
);
/* do the download */
$res=curl( $url, $options );
/* all ok? */
if( $res->info->http_code==200 ){
echo "OK";
}
/* close the file pointer */
fclose( $fp );