Writing /var/www/vhosts/w629.ws.domainking.cloud/enjoy-lei.com/lei_wiki/data/cache/8/87bf90b0253a923bba448dbae6368129.i failed
Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.
Writing /var/www/vhosts/w629.ws.domainking.cloud/enjoy-lei.com/lei_wiki/data/cache/8/87bf90b0253a923bba448dbae6368129.metadata failed
画像をサイトから自動ダウンロードするプログラム
<?php
//
// これはカーサイトの画像をダウンロードするためのプログラムです。
// 下記のサイトのみになるが、
//
//$url = "http://car.watch.impress.co.jp/docs/news/photo/20120416_526846.html";
$url = "http://car.watch.impress.co.jp/docs/news/20120606_538070.html";
$folderName = "BMW_X6_2012_06";
getCarImageData($url, $folderName);
//画像を取得ファンクション
function getCarImageData($url,$folderName){
//フォルダ作成
if(!file_exists($folderName)){
mkdir($folderName, 0700);
}
//ベースURLの設定
if ($urlPath = parse_url($url)) {
$urlPath = parse_url($url);
//echo $urlPath['host']."\n";
//echo $urlPath['path']."\n";
$baseUrl = "http://".$urlPath['host'];
}else{
$baseUrl = "http://car.watch.impress.co.jp";
}
$siteData = file_get_contents($url);
$siteData = mb_convert_encoding($siteData,'SJIS', "UTF-8");
//print_r($siteData);
//exit;
//<a href="/img/car/docs/526/846/html/013.jpg.html" target="_self">
//画像ネーム取得
if(preg_match_all('/<a href=\"(.+)\" target=\"_self\">/', $siteData, $match)) {
//print_r($match);
foreach($match[1] as $key => $value){
$imageUrl = $baseUrl.$value;
//echo $value."\n";
//echo $imageUrl."\n";
$imaData = file_get_contents($imageUrl);
//print_r($imaData);
//exit;
if(preg_match_all('/<img(.+)src=\"(.+)\" (.+)\/>/', $imaData, $mat)) {
//print_r($mat);
//exit;
$imageUrl = $baseUrl.$mat[2][0];
$pathInfo = pathinfo($mat[2][0]);
$fileName = $pathInfo["filename"];
//画像ファイルを取り出し保管する。
$imageData=file_get_contents($imageUrl,FILE_BINARY);
if($imageData){
file_put_contents("./".$folderName."/".$fileName.".jpg",$imageData);
}
}else{
echo "nai\n";
}
}
}else{
echo "nai";
}
}
exit;
?>