当前位置: 代码迷 >> PHP >> PHP获取远路文件信息
  详细解决方案

PHP获取远路文件信息

热度:486   发布时间:2012-08-24 10:00:21.0
PHP获取远程文件信息

    $url = 'http://.../config';
    $username = 'username';
    $password = 'password';
    
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FAILONERROR, 1);
    curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: text/plain'));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $result = curl_exec($curl);

    curl_close($curl);
    
    // 获取的内容
    echo $result;

  相关解决方案