php if문 처리

php if문 처리

QA

php if문 처리

본문

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

 

위 페이지에 가면 

<html>
  <head>
  <title>error</title>
  </head>
  <body>
  <br>Not Found
  </body>
  </html>

 

이러게 나오는 데요 

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

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

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

echo "이미지가 있다";

}else{

echo "이미지가 없다";

}

했는데 안되네요 ㅠ,ㅠ,

이 질문에 댓글 쓰기 :

답변 1

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';   
}
답변을 작성하시기 전에 로그인 해주세요.
전체 133
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT