1

我正在尝试获取位于标准 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]
4

2 回答 2

2

通过这样做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应该很有用

于 2013-10-30T15:25:12.210 回答
1

知道答案是给出和接受的,
这是文件给出的正确方法。

<?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

于 2016-03-15T17:57:07.043 回答