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";
I have even tried
$fileD = "file"."date('m-d-Y H:i:s A e')".".csv";
Then I copy the files
$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.
Any help with this is great appreciated.
EDIT: 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');
Never mind. Colons are not allowed in the file naming convention in windows. Overlooked that part. Thanks Michael.
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.