简体   繁体   English

fopen 不使用 date() 创建文件

[英]fopen doesn't create a file with date()

I have a code which should create a file called "Report (xxxx-xx-xx - xx:xx:xx XX).txt", but it doesn't creates.我有一个代码应该创建一个名为“Report (xxxx-xx-xx - xx:xx:xx XX).txt”的文件,但它不会创建。 I already searched for like 3 hours on a solution for this, but I didn't find any.我已经为此搜索了大约 3 个小时的解决方案,但我没有找到任何解决方案。

Here is the code:这是代码:

$myfile = fopen("Report (" . date("d/m/Y - h:i:s") . ").txt", "w") or die("Unable to open file!");

(This is on line 34) (这是在第 34 行)



And here is the error I get:这是我得到的错误:

Warning: fopen(Report (29/07/2020 - 04:35:54).txt): failed to open stream: No such file or directory in C:\xampp\htdocs\worcome\recibir\index2.php on line 34
Unable to open file!

(The "Unable to open file!" text is from the "or die()" part) (“无法打开文件!”文本来自“or die()”部分)

Remove the / (slash) in the file name and it should work.删除文件名中的/ (slash) ,它应该可以工作。 It is prohibited in file naming.文件命名中禁止。 IT is considered unsafe IT 被认为是unsafe

This should do这应该做

$myfile = fopen("(Report " . date("d-m-Y - h:i:s") . ").txt", "w") or die("Unable to open file!");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM