문제

어떤 이유로 어떤 이유로 아래 의이 PHP 코드는 작동하지 않으므로 파악할 수 없습니다.

매우 이상합니다. file_exists는 이미지가 존재한다는 것을 알지 못하는 것 같습니다. 좋은 파일 경로가 file_exists 함수에 삽입되고 있는지 확인했으며 여전히 작용 중입니다.

file_exists를! file_exists로 변경하면 존재하는 이미지와 존재하지 않는 이미지를 반환합니다.

define('SITE_PATH2', 'http://localhost/');

$noimg = SITE_PATH2. 'images/userphoto/noimagesmall.jpg';
$thumb_name = 'http://localhost/images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if (file_exists($thumb_name)) {
    $img_name = $thumb_name;
}else{
    $img_name = $noimg;
}
echo $img_name;
도움이 되었습니까?

해결책

file_exists() URL이 아닌 하드 드라이브에서 파일 경로를 사용해야합니다. 따라서 더 많은 것이 있어야합니다.

$thumb_name = $_SERVER['DOCUMENT_ROOT'] . 'images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if(file_exists($thumb_name)) {
    some_code
}

http://us2.php.net/file_exists

다른 팁

문서 말하다:

PHP 5.0.0 기준 으로이 기능은 약간 URL 포장지. 인용하다 지원되는 프로토콜/포장지 목록 어떤 포장지가 지원하는지 목록 stat() 기능의 가족.

file_exists 로컬 파일 시스템에서만 작동합니다.

그러니 당신이 사용하는 경우 이것을 시도하십시오 로컬 호스트:

$thumb_name = 'images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';
if (file_exists($_SERVER['DOCUMENT_ROOT'].$thumb_name)) {
    $img_name = SITE_PATH2.$thumb_name;
} else {
    $img_name = $noimg;
}

외부 URL을 사용할 수있는 옵션을 활성화 했습니까? php.ini로 설정할 수 있습니다.

allow_url_fopen = 1

http://php.net/manual/en/function.file-exists.php

아래의 의견을 확인 했습니까?

그 부분 만 읽지 만 몇 가지 문제가있는 것 같습니다.

캐싱은 문제 일 수 있습니다. FTP URL을 열 때 항상 사실을 반환합니다 (주석에서 말합니다) ...

파일 경로를 작성해야합니다 "file:///C:/Documents%20and%20Settings/xyz/Desktop/clip_image001.jpg".

아래에서 시도하십시오. 저를 위해 일하고 있습니다

define('SITE_PATH2', 'http://localhost/');
$noimg = SITE_PATH2. 'images/userphoto/noimagesmall.jpg';
$thumb_name = 'http://localhost/images/userphoto/1/2/2/59874a886a0356abc1_thumb9.jpg';

if ($fileopen = @fopen($thumb_name)) {
    $img_name = $thumb_name;
    fclose($fileopen);
}else{
    $img_name = $noimg;
}
echo $img_name;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top