yogibear Posted July 14, 2007 Share Posted July 14, 2007 Hi everyone quick question about adding the date to a file name this is what i have so far $date = date("Y/m/d"); // Open file 'backup.csv'. $f = fopen ('backup.csv','w'); // Put all values from $out to backup.csv. fputs($f, $out); fclose($f); header('Content-type: application/csv'); header('Content-Disposition: attachment; filename="backup.csv"'); readfile('backup.csv'); ?> I have tried a few things but got so many errors I thought I would remove them and ask for help before the whole thing stopped working. Many thanks yogi Quote Link to comment Share on other sites More sharing options...
Caesar Posted July 14, 2007 Share Posted July 14, 2007 <?php $filename = date("m_d_Y",time()).'backup.csv'; header('Content-Disposition: attachment; filename="'.$filename.'"'); ?> Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted July 14, 2007 Share Posted July 14, 2007 Well you do not state what your problem are nor what you want to do, but it seems to have something to do with adding a date to a file name... It can be done very easily: <?php //Get the date. Do _NOT_ use slashes! $date = date("Y-m-d"); //Create the filename variable from a string, the date and an extension $filename = 'backup_' . $date . '.csv'; ?> If the $date variable in the script you posted was the one you used to create the filename it failed because you used slahes in your date. You can't have slashes or backslashes in a filename since they separate each "element" in the path (drive, folder, filename). backup_2007/07/14.csv would be a file named 14.csv inside a folder called 07 which is inside a folder called backup_2007... Quote Link to comment Share on other sites More sharing options...
yogibear Posted July 15, 2007 Author Share Posted July 15, 2007 Hi thanks for your help works perfectly now many thanks yogi Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted July 15, 2007 Share Posted July 15, 2007 Good Remember to mark the topic as Solved... http://www.phpfreaks.com/forums/index.php/topic,118758.0.html Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.