2017-12-16 11 views
1

컬에서 json 결과의 캐시를 원하지만 오류가 발생합니다. function grabe ($ url, $ dir, $ rename, $ time = '0', $ format = 'json') {PHP CURL 및 JSON 캐시 결과

$tmp_dir = 'cache'; 
$dir=$tmp_dir.$dir; 
$rename=md5($rename); 
$file=$dir.'/'.$rename.'.'.$format; 
if(!is_dir($dir)) {mkdir($dir, 0755);} 
$cachetime=(60*$time); 


if (file_exists($file) && time() - $cachetime < filemtime($file)) 
{ 
    $rawdata=file_get_contents($file); 
    return $rawdata; 
}else 
{ 
    $ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
$uaa = $_SERVER['HTTP_USER_AGENT']; 
curl_setopt($ch, CURLOPT_USERAGENT, "User-Agent: $uaa"); 
$rawdata=curl_exec ($ch); 
curl_close ($ch); 
if($rawdata){ 
$fp = fopen("$file",'w'); 
fwrite($fp, $rawdata); 
fclose($fp);  
return $rawdata; 
    } 

}} 

eror 말하는 출력 :

Fatal error: Uncaught ArgumentCountError: Too few arguments to function grabe(), 1 passed in /home/hdmoviewap/public_html/index.php on line 182 and at least 3 expected in /home/hdmoviewap/public_html/core/init.php:3 Stack trace: #0 /home/hdmoviewap/public_html/index.php(182): grabe('https://www.goo...') #1 {main} thrown in /home/hdmoviewap/public_html/core/init.php on line 3 

내 182 라인의 index.php 당신이 grabe의 능을 호출하기 때문에입니다

$grab=grabe('https://www.googleapis.com/youtube/v3/search?key='.$key.'&part=snippet&order=relevance&maxResults=20&q=Latest+Bollywood+Video&type=video'); 

답변

1

을 불었다 단지 URL이 있지만 값이없는 URL은 입니다.이름은입니다. 그것은 사랑하는 해결하는 방법

$grab=grabe('https://www.googleapis.com/youtube/v3/search?key='.$key.'&part=snippet&order=relevance&maxResults=20&q=Latest+Bollywood+Video&type=video', 'dir', $rename); 
+0

:

그래서, 당신은 뭔가를해야합니까? –

+0

두 개 이상의 매개 변수를 전달하십시오. $ grab = grabe (url)을 수행하고 $ grab = grabe (url, 'directory', 'rename')을 실행해야합니다 – jeprubio

+0

여기서 182 행의 index.php? –