Jump to content

[SOLVED] the date in a filename


yogibear

Recommended Posts

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

Link to comment
Share on other sites

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...

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.