Php:迭代dir路径并创建文件夹(如果不存在)

时间:2016-07-04 12:32:00

标签: php path iterator directory

我想确保路径中的每个文件夹都存在。

$Path = "NamFdr1/NamFdr2/NamFdr3/NamImj.jpg"

E.g:

  • 首先检查"NamFdr1"是否存在,如果不存在,
  • 然后检查"NamFdr2"是否存在,如果没有创建;等等。

如何使用内置函数执行此操作?

1 个答案:

答案 0 :(得分:1)

试试这个,

DROP TABLE IF EXISTS books;

CREATE TABLE books
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
,name VARCHAR(50) NOT NULL
,FULLTEXT(name)
) ENGINE = MyISAM;

INSERT INTO books VALUES
(1,'Me Before You'),
(2,'How To Win Friends...'),
(3,'The Girl on the Train'),
(4,'After You'),
(5,'We Were Liars');

DROP TABLE IF EXISTS tags;

CREATE TABLE tags
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY
,tag VARCHAR(20) NOT NULL
);

INSERT INTO tags VALUES
(1,'romance'),
(2,'thriller'),
(3,'fantasy'),
(4,'science fiction'),
(5,'drama'),
(6,'friends');

DROP TABLE IF EXISTS books_tags;

CREATE TABLE books_tags
(book_id INT NOT NULL
,tag_id INT NOT NULL
,PRIMARY KEY(book_id,tag_id)
);

INSERT INTO books_tags VALUES
(1,1),
(1,3),
(2,3),
(3,3),
(3,5),
(4,1),
(4,5),
(4,6),
(5,2),
(5,6);

我希望它会有所帮助