简体   繁体   English

PHP Glob不匹配所有文件

[英]PHP glob Not matching all files

I'm trying to find out what files exist on my hdd and what files don't. 我试图找出我的硬盘上存在哪些文件,哪些文件不存在。 I've made a script which has worked for most of the files but it's saying it can't find this file even though it's there, There are also a few others that don't work. 我已经编写了一个脚本,该脚本适用于大多数文件,但是它说即使存在该文件也找不到该文件,还有一些其他文件不起作用。

I have this file here, Which i've confirmed exists: 1430 - Theta (J)(Independent).nds 我在这里已确认存在此文件:1430-Theta(J)(Independent).nds

if i do the following: 如果我执行以下操作:

$files = glob("/var/www/html/files/*");

I can see the file that i'm looking for, However when i try the following: 我可以看到我要查找的文件,但是当我尝试以下操作时:

$findFile = glob("/var/www/html/files/1430 - Theta (J)(Independent).nds");

It keeps coming back as nothing found. 由于找不到任何东西,它不断回来。 Is there something i need to escape on this file ? 我需要对此文件进行转义吗?

Full Code: 完整代码:

$query = "SELECT r_id, r_url FROM games WHERE r_url <> '' && r_uploaded = '' && r_console = 'nds' ORDER BY RAND() LIMIT 1";
$sql = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($sql)) {


$fileName = substr($row['r_url'], strrpos($row['r_url'], '/') + 1);

$path = "/var/www/html/files";

echo "Full URL = $row[r_url] <br />";
echo "File Name = $fileName <br />";
echo "Full Path = $path/$fileName";
echo "ID = $row[r_id] <br /> <br />";
$findFile = glob("$path/$fileName");


    if(!empty($findFile[0]) && !empty($row['r_id'])) {
        echo "File was found";      
    } else {
        echo "File not found";
    }
}

If you are running on Linux or Unix you need to escape the path. 如果您在Linux或Unix上运行,则需要转义路径。

$findFile = glob("/var/www/html/files/1430\ -\ Theta\ \(J\)\(Independent\).nds");

To do this better you can use the escapeshellcmd command. 为了更好地做到这一点,您可以使用escapeshellcmd命令。 http://php.net/manual/en/function.escapeshellcmd.php http://php.net/manual/zh/function.escapeshellcmd.php

$findFile = escapeshellcmd($findFile);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM