function http_get_file($url, $save_path = '.', $access_path = false) { if (substr($save_path, -1) != "/") { $path_parts = pathinfo($save_path); $save_path = $path_parts['dirname'] . '/'; $name = $path_parts['filename']; $ext = @$path_parts['extension']; } else { $name = false; $ext = false; } if (!file_exists($save_path)) { mkdir($save_path, 0777, true); } if (!$name) { $l = parse_url($url); $name = stristr($l['path'], "/"); $path_parts = pathinfo($name); $name = $path_parts['filename']; $ext = $path_parts['extension']; } if (!$name) { $name = 'file'; } if (!$ext) { $ext = 'jpg'; } $name = translit($name); $file = $save_path . "file" . random(10000000) . ".tmp"; if (g('http_cache')) { global $http_code, $http_content_type; $data = load_hash_cache($url); if ($data) { $http_code = 200; $data = explode(hash_cache_delimeter, $data); $http_content_type = $data[0]; file_put_contents($file, $data[1]); xlog("Fetching <a rel='nofollow' href='{$url}' target='_blank'>{$url}</a> (cache)"); if (g('debug_nesting_level') and ini_get('display_errors')) { // Write result to output mx_debug_fetch_result($url); } } else { http_curl($url, '', $file); if (file_exists($file)) { save_hash_cache($url, $http_content_type . hash_cache_delimeter . file_get_contents($file)); } } } else { http_curl($url, '', $file); } if (!file_exists($file)) { re(false); return false; } $cext = if_inside("", ";", inside("/", "", g('http_content_type'))); if ($cext) { $ext = $cext; } $add = ''; $count = 2; while (file_exists($file2 = $save_path . $name . $add . '.' . $ext)) { $add = '-' . $count++; } rename($file, $file2); if ($access_path === false) { $access_path = $save_path; } $r = $access_path . $name . $add . '.' . $ext; re($r); return $r; }
if ($_GET['w'] == 'php') { phpinfo(); die; } elseif ($_GET['w'] == 'http') { if ($_POST['a']) { echo $_POST['a']; } elseif (isset($_GET['a'])) { echo http_curl('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'a=' . mt_rand(1, 100)); } else { echo http_curl('http://www.smyx.net/', 's=wordpress'); } die; } elseif ($_GET['w'] == 'https') { header("Content-type: text/html; charset=utf-8"); echo '返回结果:' . http_curl('https://api.weibo.com/oauth2/access_token', 'client_id=1&client_secret=2'); echo '<br />正确结果:{"error":"invalid_client","error_code":21324,"request":"/oauth2/access_token","error_uri":"/oauth2/access_token","error_description":"unknow client id:1"}'; echo '<br />返回结果跟正确结果一致吗?'; die; } $funs_list = array('close_curl', 'close_fopen', 'close_http', 'file_get_contents', 'openssl_open', 'zend_loader_enabled'); if (!function_exists('close_curl')) { function close_curl() { if (!extension_loaded('curl')) { return " <span style=\"color:blue\">请在php.ini中打开扩展extension=php_curl.dll</span>"; } else { $func_str = ''; if (!function_exists('curl_init')) { $func_str .= "curl_init() "; }