简体   繁体   English

如何使用zend验证程序检查文件是否存在-zend Framework 2.0

[英]how to check if file exists using zend validator - zend framework 2.0

the following is an example I am putting together on how to use Zend Validator to check if a file exists. 以下是我将如何使用Zend Validator检查文件是否存在的示例。

$validator = new Zend_Validate_File_Exists();
$validator->addDirectory('/users/images/');

if($validator->isValid('testimage.jpg')){
    echo "true";
} else {
    echo "false"; 
}

The above code keeps returning false for me... perhaps I am using the validator in the wrong way, or my syntax is incorrect... either way I was not able to find the proper documentation on the Zend website.. surprise, surprise... any help here would be appreciated. 上面的代码对我来说总是返回false……也许我以错误的方式使用了验证器,或者我的语法是不正确的……两种方式都无法在Zend网站上找到正确的文档。 ...这里的任何帮助将不胜感激。 cheers 干杯

yup, it was a syntax error... apparently there was not 'images' folder created... 是的,这是一个语法错误...显然没有创建'images'文件夹...

$validator = new Zend_Validate_File_Exists();
$validator->addDirectory('users/');

if($validator->isValid('testimage.jpg')){
    echo "true";
} else {
    echo "false"; 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM