2014-09-11 87 views
0

我想只找到那些来自某个目录的文件,它等于数据库中的数组名称。 总之,我有这样的代码findFiles by where file name = some name?

$array = array(
    'img1.jpg','img2.jpg' 
); 
$array = serialize($array); 
$model->file=$array; 
$model->save(); 
// saved all the names in database and then: 

$files = unserialize($model->file); 
// and now, i have an array with the names: 
Array 
(
    [0] => img1.jpg 
    [1] => img2.jpg 
    [2] => img3.jpg 
) 
$path = 'files'; 
$data = CFileHelper::findFiles($path); // an array with files 

,并在这里,我想要做的事等;从$数据或在$数据文件名称= $文件的文件名

回答

0

回声文件找到$文件,你为什么不使用scandir()

$data = array('img1.gif','img2.gif'); // array of files from database 
$files = scandir('/path/of/directory'); 
var_dump(array_intersect($data, $files)); 

阅读sacndir()array_intersect()

+0

好吧,我心底尝试。谢谢你的回答。 – Nick 2014-09-12 10:54:55

相关问题