PHP代理webdav 123云盘示例
2025-11-01原创插件祥技术支持13°c
A+ A-php代理webdav 123云盘示例
<?php
error_reporting(0);
// 配置WebDAV连接信息
$webdavUrl = 'https://webdav.123pan.cn/webdav';
$username = '178********';
$password = 'lo****ar';
$REQUEST_URI = $_SERVER['REQUEST_URI'];
$REQUEST_URI = preg_replace('/\?.+$/', '', $REQUEST_URI);
$remoteFilePath = substr($REQUEST_URI, 4);
$getinfo = getinfo($webdavUrl, $username, $password, $remoteFilePath);
if($getinfo['http_code'] != 302){
header('HTTP/1.1 '. $getinfo['http_code']);
}else{
if(!$getinfo['redirect_url'])
{
header('HTTP/1.1 404 Not Found');
}else{
new_header($remoteFilePath);
$url = $getinfo['redirect_url'];
echo echo_file_content($url);
}
}
function getinfo($webdavUrl, $username, $password, $remoteFilePath)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $webdavUrl. $remoteFilePath);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $username. ':'. $password);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
$response = curl_exec($ch);
$getinfo = curl_getinfo($ch);
return $getinfo;
}
function echo_file_content($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'accept-language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'cache-control: max-age=0',
'priority: u=0, i',
'sec-ch-ua: "Microsoft Edge";v="129", "Not=A?Brand";v="8", "Chromium";v="129"',
'sec-ch-ua-mobile: ?0',
'sec-ch-ua-platform: "Windows"',
'sec-fetch-dest: document',
'sec-fetch-mode: navigate',
'sec-fetch-site: same-site',
'sec-fetch-user: ?1',
'upgrade-insecure-requests: 1',
'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0',
]);
$response = curl_exec($ch);
return $response;
}
function new_header($url){
ob_end_clean();
$url_array = explode('.', $url);
$name = $url_array[count($url_array)-1];
header('Content-Disposition: inline');
switch ($name) {
case 'jpg':
header('Content-Type: image/jpeg');
break;
case 'jpeg':
header('Content-Type: image/jpeg');
break;
case 'png':
header('Content-Type: image/png');
break;
case 'gif':
header('Content-Type: image/jpeg');
break;
default:
header('Content-Disposition: attachment');
header('Content-Type: application/octet-stream');
break;
}
}123云盘分享
更新时间:2025年11月05日 11:43:13



