/** * ファイルをダウンロード保存する */ public static function fileDownload($url, $localfile, $disp_error = true, $trace_redirection = false) { global $_conf; $perm = isset($_conf['dl_perm']) ? $_conf['dl_perm'] : 0606; if (file_exists($localfile)) { $modified = http_date(filemtime($localfile)); } else { $modified = false; } // DL $wap_ua = new WapUserAgent(); $wap_ua->setTimeout($_conf['http_conn_timeout'], $_conf['http_read_timeout']); $wap_ua->setAtFsockopen(true); $wap_req = new WapRequest(); $wap_req->setUrl($url); $wap_req->setModified($modified); if ($_conf['proxy_use']) { $wap_req->setProxy($_conf['proxy_host'], $_conf['proxy_port']); } $wap_res = $wap_ua->request($wap_req); // 1段階だけリダイレクトを追跡 if ($wap_res->isRedirect() && array_key_exists('Location', $wap_res->headers) && ($trace_redirection === true || $trace_redirection == $wap_res->code)) { $wap_req->setUrl($wap_res->headers['Location']); $wap_res = $wap_ua->request($wap_req); } // エラーメッセージを設定 if ($wap_res->isError() && $disp_error) { $url_t = self::throughIme($wap_req->url); $info_msg_ht = "<p class=\"info-msg\">Error: {$wap_res->code} {$wap_res->message}<br>"; if ($wap_res->isRedirect() && array_key_exists('Location', $wap_res->headers)) { $location = $wap_res->headers['Location']; $location_ht = htmlspecialchars($location, ENT_QUOTES); $location_t = self::throughIme($location); $info_msg_ht .= "Location: <a href=\"{$location_t}\"{$_conf['ext_win_target_at']}>{$location_ht}</a><br>"; } $info_msg_ht .= "rep2 info: <a href=\"{$url_t}\"{$_conf['ext_win_target_at']}>{$wap_req->url}</a> に接続できませんでした。</p>"; self::pushInfoHtml($info_msg_ht); } // 更新されていたら if ($wap_res->isSuccess() && $wap_res->code != 304) { if (FileCtl::file_write_contents($localfile, $wap_res->content) === false) { p2die('cannot write file.'); } chmod($localfile, $perm); } return $wap_res; }