在php中复制之前将日期附加到文件名 [英] Append date to filename before copy in php

查看:143
本文介绍了在php中复制之前将日期附加到文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在复制PHP之前将日期附加到文件名。

I am trying to append date to the file name before copying in PHP.

$fileS = "file.csv";
$date = date('m-d-Y H:i:s A e');
$fileD = "file$date.csv";

我甚至尝试过

$fileD = "file"."date('m-d-Y H:i:s A e')".".csv";

然后我复制文件

$Confirm = copy($fileS, $fileD);

我知道我应该检查文件是否存在等等,但为了简单起见问题我使用这个:)。

I know I should check if the file exists etc etc but for the sake of simplicity to ask the question I am using this :).

我假设这是与复制功能,读取连接的字符串有关。我可能在这里错了。

I am assuming it's something to do with the copy function that doesn't read concatenated strings. I may be wrong here.

任何帮助非常感谢。

编辑:是问题不是$ fileD。任何类型的连接都可以工作。 (感谢Greenisha)。

The colon seems to be the problem not the $fileD. Any type of concatenation would work. (Thanks to Greenisha).

这个工作,但任何想法,使其与冒号一起使用。用' - '代替':'似乎很奇怪。

This one works but any ideas to make it work with the colon. It seems weird to have the time with '-' instead of ':'.

$date = date('m-d-Y H-i-s A e');

没关系。在Windows中的文件命名约定中不允许冒号。忽略了那一部分。感谢迈克尔。

Never mind. Colons are not allowed in the file naming convention in windows. Overlooked that part. Thanks Michael.

我现在在windows中创建这个,但当它到生产,它将在UNIX。如果我改变它,结肠会在那里工作吗?任何建议将有用的路上。谢谢你的帮助。

I am creating this in windows now but when it goes to production it will be in in UNIX. So will the colon work there if I change it? Any suggestion will be useful down the road. Thanks for your help.

推荐答案

尝试使用不包含冒号的日期格式。

Try it using a date format that doesn't include colons. Colons are not permitted in Windows filenames, and perhaps other filesystem types.

// Try, for example
$fileD = "file".date('m-d-Y-His A e').".csv";

这篇关于在php中复制之前将日期附加到文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆