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