📖
PHP 파일 존재 여부 파악하기(로컬 파일 존재 및 원격지 파일 존재)
페이지 정보
본문
1. 로컬서버에서 파일존재하는지 확인[code]<?
$local_file_name = "./img/파일명.png";
function localFileExist($filepath) {
if(file_exists($filepath)) {
return true;
} else {
return false;
}
}
?>
<? if(localFileExist($local_file_name) == 1) { ?>
파일이 존재합니다.
<? } else { ?>
파일이 존재 하지 않습니다.
<? } ?>[/code]
2. 원격지에 파일이 존재하는지 확인[code]<?
$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 { ?>
원격지에 파일이 존재 하지 않습니다.
<? } ?>[/code]
$local_file_name = "./img/파일명.png";
function localFileExist($filepath) {
if(file_exists($filepath)) {
return true;
} else {
return false;
}
}
?>
<? if(localFileExist($local_file_name) == 1) { ?>
파일이 존재합니다.
<? } else { ?>
파일이 존재 하지 않습니다.
<? } ?>[/code]
2. 원격지에 파일이 존재하는지 확인[code]<?
$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 { ?>
원격지에 파일이 존재 하지 않습니다.
<? } ?>[/code]
댓글목록
등록된 댓글이 없습니다.
![]() ![]() |