php if문 처리

php if문 처리

QA

php if문 처리

답변 1

본문

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';   
}
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 133
© SIRSOFT
현재 페이지 제일 처음으로