Jump to content

Quick Variable Question


Warptweet

Recommended Posts

Pretend I have a form...

Flash Name: _ _ _ _ _ _

And in process.php, it creates a file using the inputted name...

[code]$ourFileName = $_POST['flashname'];
$ourFileHandle = fopen($ourFileName, 'w') or die("Sorry, cannot create file.");
fclose($ourFileHandle);
[/code]

Of course, in this case it is creating a file.
Although, when it creates a file from what the user typed inside the form field, is the file create as a .txt file? Whats the default file extension when a file is created and written in? If not, then how can I improvise that code so that the file name is $ourFileName, but with .txt extension?
Link to comment
https://forums.phpfreaks.com/topic/33185-quick-variable-question/
Share on other sites

There is no default file type when you create a file. If you want to create a file with a "txt" file type you need to give it one:
[code]<?php
$ourFileName = $_POST['flashname'];
$ourFileHandle = fopen($ourFileName . '.txt', 'w') or die("Sorry, cannot create file.");
fclose($ourFileHandle);
?>[/code]

Ken

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.