timmah1 Posted August 20, 2008 Share Posted August 20, 2008 I have a form that exports everything in the database into a csv file. It works fine, but what I can't figure out is how to change the file to the date for which is selected. This is what I have $date = $_POST['year']."-".$_POST['month']."-".$_POST['day']; $file = "$date.csv"; function exportMysqlToCsv($table,$filename = '$file') ... But the file name always ends up being $file.csv. How would I fix this? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/120464-solved-change-file-name/ Share on other sites More sharing options...
Lamez Posted August 20, 2008 Share Posted August 20, 2008 http://us.php.net/rename Link to comment https://forums.phpfreaks.com/topic/120464-solved-change-file-name/#findComment-620738 Share on other sites More sharing options...
Lamez Posted August 20, 2008 Share Posted August 20, 2008 $date = $_POST['year']."-".$_POST['month']."-".$_POST['day']; $file = "$date.csv"; function exportMysqlToCsv($table,$filename = '$file') rename($filename, $date); Link to comment https://forums.phpfreaks.com/topic/120464-solved-change-file-name/#findComment-620739 Share on other sites More sharing options...
timmah1 Posted August 20, 2008 Author Share Posted August 20, 2008 for some reason, i'm getting errors Warning: rename(export.csv,2008-01-1.csv) [function.rename]: No such file or directory in /home/cheezy/public_html/writegov/admin/exportcsv.inc.php on line 65 my code is this function exportMysqlToCsv($table,$filename = 'export.csv') { $date = $_POST['year']."-".$_POST['month']."-".$_POST['day']; $file = "$date.csv"; rename($filename, $file); This goes with no problem naming the file export.csv, but when I add this rename(), I get the error Link to comment https://forums.phpfreaks.com/topic/120464-solved-change-file-name/#findComment-620740 Share on other sites More sharing options...
unrelenting Posted August 20, 2008 Share Posted August 20, 2008 You probably need to rename it AFTER the script has run it's course. Link to comment https://forums.phpfreaks.com/topic/120464-solved-change-file-name/#findComment-620744 Share on other sites More sharing options...
timmah1 Posted August 20, 2008 Author Share Posted August 20, 2008 I got it. Thanks for everybody's help Link to comment https://forums.phpfreaks.com/topic/120464-solved-change-file-name/#findComment-620766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.