mrdarb mrdarb - 1 year ago 78
PHP Question

PHP Rename suing variable, throwing error

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.

Answer Source

Change the first code line to:

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download