PHP'nin file_exists () benim için çalışmaz?

6 Cevap php

Aşağıda bu PHP kod çalışmaz nedense, ben onu anlamaya olamaz.

It is very strange, file_exists does not seem to see that the image does exist, I have checked to make sure a good file path is being inserted into the file_exists function and it is still acting up

Ben! File_exists için file_exists değiştirirseniz bir mevcut görüntüleri ve yoktur olanları iade edecek

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;

6 Cevap

file_exists () sabit sürücü, bir URL dosya yolunu kullanmak gerekiyor. Böylece daha fazla gibi bir şey olmalı:

$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%5Fexists

docs ki:

PHP 5.0.0 sürümünden itibaren bu işlev aynı zamanda some URL sarmalayıcıları ile kullanılabilmektedir. Işlevsellik desteği stat() aile sarmalayıcıların listesi için List of Supported Protocols/Wrappers bakın.

Eğer harici URL'leri kullanmanızı sağlar seçeneği etkin mi? Php.ini de ayarlayabilirsiniz:

allow_url_fopen = 1

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

Aşağıdaki yorumlar kontrol ettin mi?

Sadece bunun parçaları okuma, ancak bazı sorunlar var gibi görünüyor.

Caching may be a problem. When opening FTP urls it always returns true (they say in the comments) ...

Sen "file:///C:/Documents%20and%20Settings/xyz/Desktop/clip_image001.jpg" gibi dosya yolunu yazmak zorunda.