2012-09-13 2 views
0

궁금한데, 내 서버의 루트 디렉토리 외부의 파일에 어떻게 액세스 할 수 있습니까?cURL - 서버 루트 디렉토리 외부의 파일 열기

<?php 
$location = "ABSOLUTE-PATH/FILE.mp3"; 

$ch = curl_init($location); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_FILETIME, true); 
$data = curl_exec($ch); 
$timestamp = curl_getinfo($ch, CURLINFO_FILETIME); 
curl_close($ch); 
if ($data === false) { 
    echo 'CURL Failed'; 
    exit; 
} 
//Get file size 
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) { 
    $contentLength = (int)$matches[1]; 
} 

$begin = 0; 
$end = $contentLength - 1; 

if (preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) 
{ 
    $begin = intval($matches[1]); 
    if (!empty($matches[2])) 
    { 
     $end = intval($matches[2]); 
    } 
} 

if (isset($_SERVER['HTTP_RANGE'])) 
{ header('HTTP/1.1 206 Partial Content'); } 
else 
{ header('HTTP/1.1 200 OK'); } 

header('Accept-Ranges: bytes'); 
header('Content-Length: ' . $contentLength); 
header("Content-Range: bytes $begin-$end/$contentLength"); 
header('Content-Type: audio/mpeg'); 
header('Cache-Control: public, must-revalidate, max-age=0'); 

if ($timestamp != -1) { //otherwise unknown 
    header("Last-Modified: " . gmdate("D, d M Y H:i:s", $timestamp) . " GMT"); 
} 

ob_clean(); 
flush(); 
echo ($data); 
exit; 
?> 

나는 컬을하지 않는 것을 사실로 알고 : 예를 들어

, /home/username/FILE.mp3

내가 현재 파일을 여는 데 사용하고 코드는 다음과 같다 상대 경로로 작업하고 루트 디렉토리 외부의 파일이 상대 링크로 취급된다고 가정합니다.

답변

0

왜 cURL을 사용합니까? 일반적으로 cURL은 HTTP를 통해 다른 서버와 통신하는 데 사용됩니다. 왜 사용하지 file, file_get_contents, fopen 또는 이와 비슷한?

관련 문제