Jump to content

Adding A file Extension


ray4498

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

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