ray4498 Posted May 15, 2009 Share Posted May 15, 2009 I am very new to this, so this should be simple. I have the code (below) and as you can see am getting a variable from the post of another page and then that is creating a file with the $_POST['quantity'] name. What I need to do is add the extension.txt to the $_POST['quantity'] name. How would I do this? <?php $ourFileName = "testFile.txt"; $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file"); fclose($ourFileHandle); $file_old = "testFile.txt"; $file_new = $_POST['quantity']; $New_Ext = ".txt" ; if(!rename($file_old, $file_new)) { echo ("Rename failed"); } ?> Link to comment https://forums.phpfreaks.com/topic/158310-adding-a-file-extension/ Share on other sites More sharing options...
cunoodle2 Posted May 15, 2009 Share Posted May 15, 2009 <?php $New_Ext = ".txt" ; $file_old = "testFile.txt"; $file_new = $_POST['quantity'].$New_Ext; ?> OR.. <?php $file_new = $_POST['quantity']; $file_new .= ".txt"; ?> Link to comment https://forums.phpfreaks.com/topic/158310-adding-a-file-extension/#findComment-834950 Share on other sites More sharing options...
ray4498 Posted May 15, 2009 Author Share Posted May 15, 2009 Thanks a lot cunoodle2, it worked perfectly Ray Link to comment https://forums.phpfreaks.com/topic/158310-adding-a-file-extension/#findComment-834969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.