首页 >后端开发 >php教程 > PHP获取远路文件信息

PHP获取远路文件信息

WBOY
WBOY原创
2016-06-13 13:20:26765浏览

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;

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn