我正在尝试获取位于标准 cakePHP 图像文件夹中的所有图像。我正在使用:
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
$dir = new Folder('/app/webroot/img/');
$files = $dir->find('.*'.png');
pr($files);
但我总是得到空数组。问题出在哪里?
当我尝试在该文件夹中制作目录时,我收到错误:
mkdir(): No such file or directory [CORE'Cake'Utility'Folder.php, line 515]
通过new Folder('/app/webroot/img/');
,您实际上是在说您的应用程序文件夹位于驱动器的根目录中,并且由于它不是,CakePHP 将尝试创建它,但它不能(那个 mkdir 错误)。
您可能需要执行类似操作
$dir = new Folder(App.imageBaseUrl);
或
$dir = new Folder(APP_DIR . DS . "webroot" . DS . "img");
.
检查 CakePHP 给你的常量来处理应该有用的路径 http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#core-definition-constants
知道答案被给出并接受,
这是文件给出的正确方式。
<?php
// Find all .png in your app/webroot/img/ folder and sort the results
$dir = new Folder(WWW_ROOT . 'img');
$files = $dir->find('.*'.png', true);
http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::find