On my WAMP localhost, this behaves as expected.
$pending_file = 'Path\To\pending.txt';
$filename = 'filename.txt';
copy($pending_file, 'Path\To\Directory\\' . $filename);
My file to be saved inside the directory structure Path->To->Directory
, with the correct filename. Note the extra \
is used to escape the \
, otherwise, the \
would escape the '
.
On my production server, which is a CentOS Linux, the same function causes the file to be saved in the root that the php file is run, with the path in the actual filename, treating the entire string as the filename alone. It creates this file.
Path\To\Directory\filename.txt
To clarify, that's not the path and the filename, that's the filename itself. The path is not included above.
I have found that my other file directory functions are working as expected, such as fopen, fclose, unlink, rename, ftp_rename, and many more. It seems to only be the copy function. The directories do exist on the server. The files that are created are correct. I have read the PHP documentation on copy, and found nothing in the docs or the comments.
Why is the copy() function giving this behavior on the server?