php - 修复文件夹结构的脚本
我正在更改在网站后端保存文件的方式,从:
uploads/item/x/subitem/y/document.pdf
其中 x 和 y 是整数 id,将其更改为:
uploads/item/x/subitem/y/report/document.pdf
我还需要更改当前文件夹目录,该目录有超过 1000 条记录。有没有一种好的方法可以在 php 中修复此结构,而无需处理嵌套循环中的每个文件夹,我只需要在文档之前添加另一个文件夹即可。
编辑:
这是我试图找到的命令!
foreach(glob('uploads/item/*/subitem/*/*') as $filePath)
谢谢你们的帮助。
I am changing the way I save files on the back-end of my website from:
uploads/item/x/subitem/y/document.pdf
Where x and y are integer id's, changing it to:
uploads/item/x/subitem/y/report/document.pdf
I need to change the current folder directory as well, which is over 1000 records. Is there a nice way to fix this structure in php without addressing each folder in nested loops, I just need to add another folder before the document.
EDIT:
This was the command I was trying to find!
foreach(glob('uploads/item/*/subitem/*/*') as $filePath)
Thanks for the help guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过 php 的重命名:
Have you tried php's rename:
您不能在
y/
下创建一个文件夹report/
,然后将y/
中的所有文件移至report/?这根本不需要 PHP。
编辑:我的 bash 非常生疏,所以这里可能有很多语法错误。但这是基本思想:
Couldn't you just create a folder
report/
undery/
and then move all files iny/
intoreport/
? This doesn't require PHP at all.EDIT: My bash is very rusty so there are probably a lot of syntax errors in here. But this is the basic idea: