【发布时间】:2019-05-23 08:36:23
【问题描述】:
我似乎找不到名为 invoice 的文件夹,并且不确定我的代码是否正确
我尝试将写入更改为写入和读取,但它仍然没有为我在文件夹中创建文件...
$invoice = "------------------------------------\n";
$invoice .= "Level 1 Monthly Subscriptionplan Information\n";
$invoice .= $level1."\n";
$invoice .= "Subscriptionplan:".$row['subscriptionplan']."\n";
$invoice .= "Enrollment Date:".$row['subscriptionplandate']."\n";
$invoice .= "Monthly Fees:".$row['feesmonthly']."\n";
$invoice .= "Payment Status:".$row['paid']."\n";
$invoice .= "Expiry Date:".$row['expirydate']."\n";
$invoice .= "Payment Due Date:".$row['paidbydate']."\n";
$myfile='invoice/level1monthly/'.$_SESSION['u_uid'].'.txt';
$fh = fopen($myfile, 'w+') or die("can't open file");
fwrite($fh, $invoice);
fclose($fh);
我希望它在我的实时服务器的根目录中创建一个名为 invoice 的文件夹
3 级每月订阅计划信息 订阅计划: 注册日期: 月费:0 支付状态: 到期日: 付款截止日期:我已完成以下代码,但无法将其更改为追加
$invoice .= "Level 1 Monthly Subscriptionplan Information\n";
$invoice .= $level1."\n";
$invoice .= "Subscriptionplan:".$row['subscriptionplan']."\n";
$invoice .= "Enrollment Date:".$row['subscriptionplandate']."\n";
$invoice .= "Monthly Fees:".$row['feesmonthly']."\n";
$invoice .= "Payment Status:".$row['paid']."\n";
$invoice .= "Expiry Date:".$row['expirydate']."\n";
$invoice .= "Payment Due Date:".$row['paidbydate']."\n";
$myfile='invoice/level1monthly'.$_SESSION['u_uid'].'.txt';
$fh = fopen($myfile, 'a+') or die("can't open file");
fwrite($fh, $invoice);
fclose($fh);
} else {
$invoice = "------------------------------------\n";
$invoice .= "Level 1 Monthly Subscriptionplan Information\n";
$invoice .= $level1."\n";
$invoice .= "Subscriptionplan:".$row['subscriptionplan']."\n";
$invoice .= "Enrollment Date:".$row['subscriptionplandate']."\n";
$invoice .= "Monthly Fees:".$row['feesmonthly']."\n";
$invoice .= "Payment Status:".$row['paid']."\n";
$invoice .= "Expiry Date:".$row['expirydate']."\n";
$invoice .= "Payment Due Date:".$row['paidbydate']."\n";
$myfile='invoice/level1monthly'.$_SESSION['u_uid'].'.txt';
$fh = fopen($myfile, 'w+') or die("can't open file");
fwrite($fh, $invoice);
fclose($fh);
}
这是我更新的代码...如果新文件不存在然后附加它,这是否可以创建一个新文件?
$myfile='invoice/level1monthly'.$_SESSION['u_uid'].'.txt';
if(file_exists($myfile)) {
$invoice = "------------------------------------\n";
$invoice .= "Level 1 Monthly Subscriptionplan Information\n";
$invoice .= $level1."\n";
$invoice .= "Subscriptionplan:".$row['subscriptionplan']."\n";
$invoice .= "Enrollment Date:".$row['subscriptionplandate']."\n";
$invoice .= "Monthly Fees:".$row['feesmonthly']."\n";
$invoice .= "Payment Status:".$row['paid']."\n";
$invoice .= "Expiry Date:".$row['expirydate']."\n";
$invoice .= "Payment Due Date:".$row['paidbydate']."\n";
$fh = fopen($myfile, 'a+') or die("can't open file");
fwrite($fh, $invoice);
fclose($fh);
} else {
$invoice = "------------------------------------\n";
$invoice .= "Level 1 Monthly Subscriptionplan Information\n";
$invoice .= $level1."\n";
$invoice .= "Subscriptionplan:".$row['subscriptionplan']."\n";
$invoice .= "Enrollment Date:".$row['subscriptionplandate']."\n";
$invoice .= "Monthly Fees:".$row['feesmonthly']."\n";
$invoice .= "Payment Status:".$row['paid']."\n";
$invoice .= "Expiry Date:".$row['expirydate']."\n";
$invoice .= "Payment Due Date:".$row['paidbydate']."\n";
$myfile='invoice/level1monthly'.$_SESSION['u_uid'].'.txt';
$fh = fopen($myfile, 'w+') or die("can't open file");
fwrite($fh, $invoice);
fclose($fh);
}
【问题讨论】:
-
据我了解,使用 w 模式会尝试创建它不存在的文件,但模式 a 也会创建文件吗?
-
它已经用 w+ 模式创建了文件,但是现在如果我想追加,我需要添加一个模式来代替吗?我想,如果首先,我想创建一个新文件,然后第二个,附加到它,我将如何让它工作?
-
我在这里遇到了一些奇怪的事情,我应该将代码放在电子邮件之后还是电子邮件之前?顺序有关系吗?
-
Level 3 每月订阅计划信息订阅计划: 注册日期: 月费:0 付款状态: 到期日: 付款到期日:
-
启用错误报告。
标签: php file session directory