 |
|
|  |
| PHP 파일 존재 여부 파악하기(로컬 파일 존재 및 원격지 파일 존재) |
|
|
 |
5년 전 |
1. 로컬서버에서 파일존재하는지 확인
<?
$local_file_name = "./img/파일명.png";
function localFileExist($filepath) {
if(file_exists($filepath)) {
return true;
} else {
return false;
}
}
?>
<? if(localFileExist($local_file_name) == 1) { ?>
파일이 존재합니다.
<? } else { ?>
파일이 존재 하지 않습니다.
<? } ?>
2. 원격지에 파일이 존재하는지 확인
<?
$remot_file_name = "http://원격지 URL/파일명.png";
function remoteFileExist($filepath) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$filepath);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if(curl_exec($ch)!==false) {
return true;
} else {
return false;
}
}
?>
<? if(remoteFileExist($remot_file_name) == 1) { ?>
원격지에 파일이 존재합니다.
<? } else { ?>
원격지에 파일이 존재 하지 않습니다.
<? } ?> |
|
추천 : 418 |
추천
목록
|
|
|  |
|