我想创建一个目录,并为每个月创建一个文件夹。我希望我的目录像这样安装。根\子文件夹\月。月份文件夹内将会生成每日报告。我编码时遇到的问题是我收到语法错误,说有一个意想不到的'\'(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机器 –