我從 mysql 表中獲取了一些行
并希望將列中的資料放入檔案系統內story的新創建檔案中
并且 gettint 錯誤-路徑中的某些檔案夾-不存在
有沒有辦法自動創建所有丟失的檔案夾并最終創建檔案?.txt.txt
foreach($rows as $row){
$path = $row['pt'] . "/" . $row['title'] . ".txt";
if(!is_file($path)){
fopen($path, "w");
file_put_contents($path, $row['story']);
}
}
uj5u.com熱心網友回復:
只需使用 php mkdir - mkdir
foreach($rows as $row){
$path = $row['pt'] . "/" . $row['title'] . ".txt";
// make the folder, u can check if the folder exist, if not create it
mkdir($row['pt'] , 0777, true);
// put content
if(!is_file($path)){
fopen($path, "w");
file_put_contents($path, $row['story']);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/533062.html
標籤:php文件系统
