테스트 사이트 - 개발 중인 베타 버전입니다

php if문 처리 채택완료

열린이글1 6년 전 조회 2,643

http://liveimg.afreecatv.com/218131415_480x270.jpg?8771">http://liveimg.afreecatv.com/218131415_480x270.jpg?8771

 

위 페이지에 가면 

 
  error
 
 
  Not Found
 
 

 

이러게 나오는 데요 

php 에서 Not Found 문구를 채크해서 조건문을 만들수있나요?

만들수있으면 소스좀 부탁드려요

  if(!file_exists('http://liveimg.afreecatv.com/218131415_480x270.jpg?8771">http://liveimg.afreecatv.com/218131415_480x270.jpg?8771')) {   

echo "이미지가 있다";

}else{

echo "이미지가 없다";

}

했는데 안되네요 ㅠ,ㅠ,

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
6년 전
function remoteFileExists($url) {
    $curl = curl_init($url);

    //don't fetch the actual page, you only want to check the connection is ok
    curl_setopt($curl, CURLOPT_NOBODY, true);

    //do request
    $result = curl_exec($curl);

    $ret = false;

    //if request did not fail
    if ($result !== false) {
        //if request was ok, check response code
        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);  

        if ($statusCode == 200) {
            $ret = true;   
        }
    }

    curl_close($curl);

    return $ret;
}

$exists = remoteFileExists('http://stackoverflow.com/favicon.ico');
if ($exists) {
    echo 'file exists';
} else {
    echo 'file does not exist';   
}
로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인