【问题标题】:Makes a file named with current date d:m:Y创建一个以当前日期 d:m:Y 命名的文件
【发布时间】:2015-11-22 17:50:56
【问题描述】:

PHP

$file = fopen((string)date("d-m-Y").".php","w");
fwrite($file,'Body');
fclose($file);

正确地创建一个名为 22-11-2015 的文件。

但是

$file = fopen((string)date("d:m:Y").".php","w");
fwrite($file,'Body');
fclose($file);

创建一个名为23P826~3!!!!的文件。

为什么在 Ubuntu 中不能为文件名设置:?

【问题讨论】:

  • 冒号是 reserved character 用于 Windows 上的文件名。
  • php -r 'file_put_contents("test-".date("d:m:Y"), "");' 在 Debian 上运行良好。 (string) 是怎么回事?哦,如果你使用date("Y-m-d"),你可以按日期排序;-)
  • 您的脚本也可以正常工作。你用的是什么文件系统?我在 ext4; PHP 版本 5.6.13,$LANG en_US.utf-8。
  • 我使用 samba 和 php 5.3

标签: php ubuntu filenames


【解决方案1】:

首先,您可以查看Wikipedia Filename page 了解更多信息。

在我看来,文件名和目录名中应避免使用特殊字符,以免造成不必要的压力……

【讨论】:

    猜你喜欢
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多