- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我想循环浏览文件夹中的图像和缩略图,并将它们插入数据库。我想使用 is_dir 来过滤目录。
我有:
$images = scandir('./images/all_comics/');
$thumbs = scandir('./images/thumbnails/');
for($x=0; $x<count($images); $x++)
{
if(!is_dir($images[$x]))
{
//This shows all images WITHOUT directories
echo $images[$x];
//This is STILL adding images AND directories to database
mysql_query("INSERT INTO images (imgpath, thumbpath) VALUES ('$images[$x]', '$thumbs[$x]')");
}
}
我在 !is_dir 之后直接在那里检查,echo $images[$x],它会根据需要回显所有没有目录的图像。
但是当我检查数据库中的插入时,我看到目录已添加为记录。这是为什么?
谢谢!
最佳答案
(删除旧答案,因为问题是打字错误)
scandir
返回给定目录中的文件列表。当您使用 is_dir
时,它会在当前目录中查找这些文件。我认为你需要做的是:
if(!is_dir("./images/all_comics/" . $images[$x])) {
....
关于php - is_dir 不适用于 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12517754/
我在迭代某个目录中的所有文件时使用 is_dir 时遇到问题。代码有点小,所以我想如果我发布它你会更好地理解我的意思: $files = array(); if ($dir = @opendir(
我正在尝试开发一个 PHP MySQL 网站,其中需要 is_dir 函数,主文件夹中存在“安装”文件夹,然后转到安装文件夹(如果为 true)或继续该网站(如果错误)。 if(is_dir(
我正在尝试创建一个函数来扫描文件夹中的子文件夹,然后返回一个包含这些文件夹名称的数字数组。 这是我用来测试的代码。一旦我得到它打印出文件夹名称而不仅仅是“。”和“..” for present和上面的
我想遍历一个目录并回显所有文件夹。但是,foreach 循环只是回显出来。和.. $dir = 'content/'; $handle = scandir($dir); foreach ($handl
我正在测试目录处理功能。我有一个包含以下内容的折叠/目录: 0 个文件夹 假文件夹 我的图片文件夹 MVI_3094 动画文件 img01 jpeg 图片 等... 我写了如下代码遍历目录并打印出具体
在工作中,我继承了一个具有文件上传过程的 Web 应用程序。此过程的一部分偶尔(每两周左右一次)会触发以下错误: PHP Warning: mkdir(): File exists in {{{fi
is_dir() 函数在我的 linux 系统中不起作用。目录如下: /变量 /万维网 /html - 测试.php /代码 is_dir("/var/www/html") 返回真。但是 is_dir
我尝试使用 is_dir 函数,但即使该目录确实存在,它也总是返回 false。我是一个非常新的 Linux 用户(xubuntu),我在这里读到类似的问题,问题可能是目录权限。我尝试过使用: sud
我想循环浏览文件夹中的图像和缩略图,并将它们插入数据库。我想使用 is_dir 来过滤目录。 我有: $images = scandir('./images/all_comics/'); $thumb
我有这个功能: if (is_dir($dir)) { //are we able to open it? if ($dh = opendir($dir)) {
为什么 is_dir() 即使是目录也返回 false? 没有返回错误 $path_mysql = '/var/lib/mysql/'; if(!is_dir($path_mysql)){ e
我已在 Windows 资源管理器中将我的 Z: 驱动器映射到网络上另一台服务器上的文件共享。我可以在那里访问文件和读/写。 当我尝试从 PHP 执行 mkdir() 时,出现“没有这样的文件或目录”
我正在使用 scandir() 检查目录文件,它可以正常使用来自根目录的路径,例如/dir1/dir2/....(dir1 不在我的 .php 文件后面,它是根目录中的一个文件夹) 但是当在同一路径上
我目前的目录结构如下: C:\xampp\htdocs\PHP_Upload_Image_MKDIR 换句话说,下面的目录根本不存在。 C:\xampp\htdocs\PHP_Upload_Image
如果目录不存在,我想创建一个目录。 使用 is_dir 函数是否足以达到此目的? if ( !is_dir( $dir ) ) { mkdir( $dir ); } 或者我应该将
我有一个映射到驱动器盘符 X:\的网络驱动器,它连接到路径为“\\X-Drive\Public\Data”的外部硬盘驱动器。 我正在使用带 Apache 的 Zend Server。 我的 PHP 命
关于带有特殊字符的 is_dir,我有一个奇怪的行为:äöüàéè。 如果先写入特殊字符(例如 'à tést'、'école wat'),则代码可以正常工作(检测文件夹)。 但是如果除了特殊字符之外
我一直在为一个奇怪的问题而烦恼...据我所知,is_file() 在检查特定文件时导致段错误: if( is_file('/path/to/file.php') ){ exit 'ok'; }
PHP 的 is_dir() 的 C++ 等价物是什么? http://www.php.net/manual/en/function.is-dir.php bool is_dir ( string $
编辑:这不是 open_basedir restriction in effect. File(/) is not within the allowed path(s): 的副本.这个问题与 PHP
我是一名优秀的程序员,十分优秀!