Php 检查文件夹中包含使用glob()的模式的文件名
我需要检查文件夹中包含Php 检查文件夹中包含使用glob()的模式的文件名,php,file,glob,dir,Php,File,Glob,Dir,我需要检查文件夹中包含'.符号的文件。我使用了glob函数从服务器位置获取文件。但我不知道是否检查文件名中包含符号的任何位置。 我有如下格式的文件名学生178年级1A 我是这样做的 $report_files=glob( '/user_uploads/' . '/reportcards/' . 'term' . '_' . 10.'/*'.'.pdf' ); //this will return all files inside the folder. if(count(report_fi
'.
符号的文件。我使用了glob函数从服务器位置获取文件。但我不知道是否检查文件名中包含符号的任何位置。
我有如下格式的文件名<代码>学生178年级1A
我是这样做的
$report_files=glob( '/user_uploads/' . '/reportcards/' . 'term' . '_' . 10.'/*'.'.pdf' );
//this will return all files inside the folder.
if(count(report_files)>0)
{
//some stuff
}
else
{
}
我需要获取文件名中包含“\”的文件。我尝试了
glob( '/user_uploads/' . '/reportcards/' . 'term' . '_' . 10.'/*[_]'.'.pdf' );
但它不起作用首先,学期结束后你忘了带引号
$report_files = glob('/user_uploads/'.'/reportcards/'.'term'.'_'.10.'/*[_]'.'.pdf');
其次,在user\u上传后有两个斜杠
$report_files = glob('/user_uploads/reportcards/'.'term'.'_'.10.'/*[_]'.'.pdf');
首先,学期结束后你忘了带引号
$report_files = glob('/user_uploads/'.'/reportcards/'.'term'.'_'.10.'/*[_]'.'.pdf');
其次,在user\u上传后有两个斜杠
$report_files = glob('/user_uploads/reportcards/'.'term'.'_'.10.'/*[_]'.'.pdf');
您的正则表达式似乎不正确。这可能会满足您的要求:
// Find any file in the directory "/user_uploads/reportcards/term_10/"
// that has the file extension ".pdf"
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\.pdf");
// Find any file in the directory "/user_uploads/reportcards/term_10/"
// containing the character "_".
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\_(.*)");
// Find any file in the directory "/user_uploads/reportcards/term_10/"
// that has the file extension ".pdf" and contains the "_" character
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\_(.*)\.pdf");
如果您不完全理解正则表达式的作用,我将在下面简要介绍一下所做的工作。还有一个很好的网站可以试用常规的expresson,并提供关于如何构建它们的文档
您的正则表达式似乎不正确。这可能会满足您的要求:
// Find any file in the directory "/user_uploads/reportcards/term_10/"
// that has the file extension ".pdf"
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\.pdf");
// Find any file in the directory "/user_uploads/reportcards/term_10/"
// containing the character "_".
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\_(.*)");
// Find any file in the directory "/user_uploads/reportcards/term_10/"
// that has the file extension ".pdf" and contains the "_" character
$report_files = glob("\/user_uploads\/reportcards\/term\_10\/(.*)\_(.*)\.pdf");
如果您不完全理解正则表达式的作用,我将在下面简要介绍一下所做的工作。还有一个很好的网站可以试用常规的expresson,并提供关于如何构建它们的文档
我忘记为问题中的术语添加四分之一标记。我需要筛选其中包含下划线的文件名。我忘记为问题中的术语添加四分之一标记。我需要筛选其中包含下划线的文件名。我使用了$report\u files=glob(“\/user\u uploads\/reportcards\/term\u 10”“/*”。“'.'.'.'.'.'.'.'.'.pdf'”;//这对我很有用。谢谢你给我这个主意。我使用了$report\u files=glob(“\/user\u uploads\/reportcards\/term\u 10”“/*”);//这对我很有用。谢谢你给我这个主意。