2012-06-15 2 views
0
<?php 
// open the current directory 
$dhandle = opendir('.'); 
// define an array to hold the files 
$files = array(); 

if ($dhandle) { 
    // loop through all of the files 
    while (false !== ($fname = readdir($dhandle))) { 
     // if the file is not this file, and does not start with a '.' or '..', 
     // then store it for later display 
     if (($fname != 'index.htm') && ($fname != 'torcache.php')&& ($fname != 'error_log') && (substr($fname, 0, 5) != 'other') && (substr($fname, 0, 2) != 'dd') && 
      ($fname != basename($_SERVER['PHP_SELF']))) { 
      // store the filename 
      $files[] = (is_dir("./$fname")) ? "(Dir) {$fname}" : $fname; 
     } 
    } 
    // close the directory 
    closedir($dhandle); 
} 


function curl_upload($url,$fileFormAttribute,$file){ 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 
     curl_setopt($ch, CURLOPT_VERBOSE, 1); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
     curl_setopt($ch,CURLOPT_REFERER, 'https://torcache.net/'); 
     curl_setopt($ch,CURLOPT_ENCODING,"gzip"); 
     curl_setopt($ch, CURLOPT_POST, true); 
     $post = array($fileFormAttribute=>"@".$file); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
     $response = curl_exec($ch); 
     return $response; 
} 
foreach($files as $fname) 
{ 
error_reporting(E_ALL); 


$upload_result = curl_upload('http://torcache.net/autoupload.php','torrent','public_html/download_folder/'.$files[0]); 
} 
var_dump($upload_result); 
?> 

통해 반복하지 곱슬 곱슬? dir에있는 모든 파일을 루프하여 torcache에 게시 한 다음 다시 문자열을 제공합니다.이 배열

답변

6

마지막 줄의 네 번째 줄에 이 있습니까? 이렇게 :

+0

스크래치, 틀린 라인 (+1) – ametren

+1

그는 실제로 파일인지 확인하기 위해 다시 확인하지 않습니다. 배열을 채우는 루프가 항상 유효한 파일 이름을 포함하지는 않습니다. '$ files [] = (is_dir ("./$fname"))? "(Dir) {$ fname}": $ fname; ' – hafichuk

+0

@Scott Saunders 나는이 코드를 사용했는데 현재 디렉토리의 첫 번째 파일을 업로드하는 것입니다. –

관련 문제