Php 确定文件夹中未知文件的名称
我有很多文件夹,每个文件夹都包含两个文件:一个名为thumb,但扩展名未知,另一个我不知道。我的问题是,我怎样才能得到未知图像的路径?以下是脚本:Php 确定文件夹中未知文件的名称,php,arrays,glob,Php,Arrays,Glob,我有很多文件夹,每个文件夹都包含两个文件:一个名为thumb,但扩展名未知,另一个我不知道。我的问题是,我怎样才能得到未知图像的路径?以下是脚本: $path = 'images/2011/May/30/brfZ0ehnBKO/thumb.jpg'; $pathtofile = substr($path, 0, -9); //images/2011/May/30/brfZ0ehnBKO/ $thumbz = $pathtofiles."thumb"; $all = glob('$pathtofi
$path = 'images/2011/May/30/brfZ0ehnBKO/thumb.jpg';
$pathtofile = substr($path, 0, -9); //images/2011/May/30/brfZ0ehnBKO/
$thumbz = $pathtofiles."thumb";
$all = glob('$pathtofiles*.*');
$zip = glob('$thumbz*.*');
$remaining = array_diff($all, $zip);
$thefile = ???;
我希望$thefile等于另一个文件…在试图输出字符串中的变量值时,请确保使用双引号:
$all = glob("$pathtofiles*.*");
$zip = glob("$thumbz*.*");
看看这是否有帮助:)PHP脚本有什么问题?它不起作用吗?如果是,会发生什么?在php中,像第一行那样做是合法的吗?我的意思是一个没有引号$path的字符串来自一个数据库,我只是简化了它
$pathtofile = dirname('images/2011/May/30/brfZ0ehnBKO/thumb.jpg');
if ($handle = opendir($pathtofile)) {
while (false !== ($file = readdir($handle))) {
if(strpos($file, 'thumb') !== 0) {
$thefile = $file;
break;
}
}
closedir($handle);
}
var_dump($thefile); // null if no such file