我想創建一個目錄,併爲每個月創建一個文件夾。我希望我的目錄像這樣安裝。根\子文件夾\月。月份文件夾內將會生成每日報告。我編碼時遇到的問題是我收到語法錯誤,說有一個意想不到的'\'(T_NS_SEPARATOR)。我對此的代碼看起來像這樣。使用PHP創建一個目錄
$month = date('M');
file('Driver Check In\Void\'.$month. '\Void_'.date('m-d-y').".csv");
我也有創建月份文件夾,如果它不存在的代碼。
我該如何解決這個問題?
全碼
if(isset($_POST['Void']))
{
$month6 = date('M');
$fp6 = file('Driver Check In\Void\\'.$month6. '\Void_'.date('m-d-y'). '.csv');
$header6 = array("Date", "Customer", "Location/City", "Driver", "Cases", "Bottles", "Reason", "Comment");
$dates6 = $_POST['dates6'];
$customer2 = $_POST['customer2'];
$location2 = $_POST['location2'];
$driver6 = $_POST['drivers6'];
$cases6 = $_POST['cases6'];
$bottles6 = $_POST['bottles6'];
$reason2 = $_POST['reason2'];
$comment2 = $_POST['comment2'];
$result6 = '';
$search6 = "Date";
$line_number6 = false;
while(list($key6, $line6) = each ($fp6) and !$line_number6)
{
$line_number6 = (strpos($line6, $search6) !== FALSE);
}
if($line_number6)
{
$result6 .=
$dates6. " ,". $customer2. " ,". $location2. " ,". $driver6. " ,". $cases6. " ,". $bottles6. " ,". $reason2. " ,". $comment2. "\r\n";
}
else
{
$result6 .= implode(",", $header6). "\r\n".
$dates6. " ,". $customer2. " ,". $location2. " ,". $driver6. " ,". $cases6. " ,". $bottles6. " ,". $reason2. " ,". $comment2. "\r\n";
}
if(!is_dir('Driver Check In\Void\\'.$month6))
{
mkdir('\Driver Check In\Void\\'.$month6);
}
file_put_contents('Driver Check In\Void\\'.$month6. '\Void_'.date('m-d-y'). ".csv", $result6, FILE_APPEND);
echo "data added6";
}
\不是* nix中的有效路徑分隔符 - 嘗試/因爲Windows並不挑剔並且會接受。 – CD001
你在運行什麼操作系統? –
目前我正在Windows 7 x64 Pro機器上編寫此代碼。稍後,這將進入一個CentOs機器 –