0

Hey Guys im trying solve a tricky issue. Currently i have a folderstructure like this:

uploads/Event-12/1234-Johne-Doe/[…] uploads/Event-32/1234-Johne-Doe/[…]

So there a many events with their own folder. Within there a subfolders which are named like the id of the user (1234) followed by first and lastname. You can see that Mr. John Doe has a folder in Event-12 and also in Event-32.

But what if John Doe change his name (for whatever reason…). So i have to rename all folders recursively otherwise all links gets broken.

How to do that with PHP. I can easily rename a folder at once by giving the correct path to it. Is there any nice solution to let PHP search for all matching directories?

Greetings.

4

3 回答 3

2

您可以在此链接中列出所有文件夹并重命名您想要的文件夹。

<?php
if ($handle = opendir('.')) {
    $blacklist = array('.', '..', 'somedir', 'somefile.php');
    while (false !== ($file = readdir($handle))) {
        if (!in_array($file, $blacklist)) {
            echo "$file\n";
        }
    }
    closedir($handle);
}
?>
于 2013-02-26T16:37:15.347 回答
1

我建议创建一个递归函数,利用scandir()并重命名它找到的每个目录。

来自 PHP 手册:http ://www.php.net/manual/en/function.scandir.php

话虽如此,我建议您只使用用户 ID 作为您的文件夹名称。您永远不应该使用可以更新的变量来命名目录和存储用户数据。

于 2013-02-26T16:34:56.973 回答
0

是的,这是一个数据库驱动的应用程序吗?如果是这样,你不应该试图解决这个问题。当您心脏病发作时,医生不会对症状进行治疗 :) 您的应用程序正在为相当于三重旁路的编码而尖叫。

我建议您首先从文件夹中删除名称。重写您的脚本以仅创建具有 ID 的文件夹(我假设这是 unqiue) - 这样,他们是否更改名称都没有关系。

于 2013-02-26T16:49:24.693 回答