file_ 정보get_콘텐츠가 비어 있거나 함수가 사용할 수 없는 해결 방안으로 되돌아오기

하면, 만약, 만약...get_콘텐츠가 원격 파일의 내용을 비어 있거나 이 함수를 사용할 수 없음을 알려 줍니다. 아마도 본문은 당신을 도울 수 있을 것입니다!file_ 사용하기get_contents와 fopen은 공간을 열어야 합니다 allow_url_fopen.방법:php 편집.ini, allow_ 설정url_fopen = On,allow_url_fopen 종료 시 fopen 및 file_get_콘텐츠는 원격 파일을 열 수 없습니다.가상 호스트를 사용한다면curl 함수로 대체하는 것을 고려할 수 있습니다.curl 함수 사용 예:

$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');

좋은 웹페이지 즐겨찾기