file_ 정보get_콘텐츠가 비어 있거나 함수가 사용할 수 없는 해결 방안으로 되돌아오기
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, ‘https://www.jb51.net');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
function_exists 함수로 php가 file을 지원하는지 판단_get_콘텐츠, 그렇지 않으면curl 함수로 대체합니다.PS1, 만약 당신의 호스트 서비스 업체가curl도 닫았다면, 당신은 호스트 업체를 바꾸세요!2、allow_url_fopen을 off로 설정하면 호스트가 file_를 지원하지 않는 것은 아닙니다get_content 함수.원격 파일을 열 수 없을 뿐입니다.function_exists("file_get_contents")는 true를 반환합니다.그래서 인터넷에 떠도는'file_get_contents 함수 사용할 수 없는 해결 방법'은 여전히 문제를 해결할 수 없다.오류 코드:
if (function_exists(‘file_get_contents')) {
$file_contents = @file_get_contents($url);
}else{
$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
:
if (function_exists(‘file_get_contents')) {// file_get_contents
$file_contents = @file_get_contents($url);
}
if ($file_contents == ”) {// $file_contents
$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
최종 코드:
function file_get_content($url) {
if (function_exists(‘file_get_contents')) {
$file_contents = @file_get_contents($url);
}
if ($file_contents == ”) {
$ch = curl_init();
$timeout = 30;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
}
return $file_contents;
}
사용법: echo file_get_content(‘https://www.jb51.net');
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
file_ 정보get_콘텐츠가 비어 있거나 함수가 사용할 수 없는 해결 방안으로 되돌아오기하면, 만약, 만약...get_콘텐츠가 원격 파일의 내용을 비어 있거나 이 함수를 사용할 수 없음을 알려 줍니다. 아마도 본문은 당신을 도울 수 있을 것입니다!file_ 사용하기get_contents와 fopen은 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.