PHP Rename suing variable, throwing error

时间:2016-10-20 12:53:57

标签: php rename

I'm trying to use a variable with the rename() function to rename a file at the end of a function.

I'm creating the new file name like so;

$filenamegen = "XML_MERGE_" . date("d:h:i:s");

and then trying to use rename() like so;

rename ("F:\\a\\a\\a\\bb/tempname.xml", "F:\\a\\a\\a\\bb/" . $filenamegen . ".xml");

The above code is throwing the following error;

The filename, directory name, or volume label syntax is incorrect. (code: 123) 

If anyone has any ideas of how this could be fixed it would be much appriciated!

Many thanks as always.

1 个答案:

答案 0 :(得分:4)

Change the first code line to:

$filenamegen = "XML_MERGE_" . date("d_h_i_s");

You cannot use ":" in a file name on Windows!

相关问题