PHP file_exists目录 [英] PHP file_exists directory

查看:138
本文介绍了PHP file_exists目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用文件存在于子目录中,并遇到目录结构或其他问题。该代码从主目录调用时更早工作。



包含该命令的文件在一个子目录中,该目录位于该主目录下的一个目录。 p>

当我在一个我知道的文件中调用以下内容时,没有返回任何内容,FALSE也不是TRUE

  $ imgpath1 ='pics /'.$ userid .'_ pic.jpg'; 
$ exists = file_exists($ imgpath1);
echo1$存在; //返回1

我尝试过不同的变体的目录,例如'/ pics ...',还有'../ pics ...'以及整个url开始使用' http:// www ....'但不能让它返回一个FALSE或一个TRUE。



感谢任何建议。

解决方案

当将 true 强制转换为字符串时,您将获得 1



当将 false 强制转换为字符串时,会得到一个空字符串。



这是一个例子:

 <?php 
echo True:\。true。\\\\
;
echoFalse:\。false。\\\\
;

echoTrue length:。 strlen(。true)。 \\\
;
echoFalse length:。 strlen(。false)。 \\\

?>

运行它的输出:

  True:1
False:
True length:1
False length:0

所以在现实中, file_exists($ imgpath1)正在返回 false


I am trying to use file exists in a subdirectory and running into some problems with the directory structure or perhaps something else. This code was working earlier when called from the main directory

The file that includes the command is in a subdirectory that is one directory below the main directory of the domain.

When I call the following on a file that I know exists nothing is returned, neither FALSE nor TRUE

$imgpath1 = 'pics/'.$userid.'_pic.jpg';
$exists = file_exists($imgpath1);
echo "1".$exists;//returns 1

I have tried different variations of the directory such as '/pics...' and also '../pics...' as well as the whole url begininning with 'http://www....' but cannot get it to return either a FALSE or a TRUE.

Would appreciate any suggestions.

解决方案

When coercing true to a string, you get a 1.

When coercing false to a string, you get an empty string.

Here's an example of this:

<?php
echo "True: \"" . true . "\"\n";
echo "False: \"" . false . "\"\n";

echo "True length: " . strlen("" . true) . "\n";
echo "False length: " . strlen("" . false) . "\n"
?>

And the output from running it:

True: "1"
False: ""
True length: 1
False length: 0

So in reality, file_exists($imgpath1) is returning false.

这篇关于PHP file_exists目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆