• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

creating a file with an extension?

rapmaster

New Member
ok, I'm just wondering cuz I'm gona need to do this before I can finish a script I'm working on but how do I make a file with a certain extenion?

like I want to create a php file, how would I do that?
 
I really must be missing something here...

Save the file in your script editor as *.php.
 
Open up notepad, type up your script, then File>Save As>Save As Type:All Files>Enter filename.php>OK
 
ok guys, I'm not a retarded moron. I know how to save it as one. I want to create a file using a php script with a .php extension, how to you make files with extensions? and have a variable for a name?

like would it be

$blah = fopen($file, ".php")

or what
 
no, use:
PHP:
<?PHP
$fp = fopen("$file.php", "w");
fputs($fp, "");
fclose($fp);
?>

you can add text in between the "" in the fputs statment and it will be saved to the file. $file must be defined for this to work. But other wise, this works fine, I tested it.
 
ok, so I can just go

$file.php

like if its from a query using post,

script.php?file=yadayada

and I call

fopen("$file.php", "w");

it will call yadayada.php and doing the rest will write and create the file right? I'm gona test it out. Thx for the help
 
originally posted by rapmaster
ok, so I can just go

$file.php

like if its from a query using post,

script.php?file=yadayada

and I call

fopen("$file.php", "w");

yes, except you need those other 2 lines of code or it won't work.
 
Back
Top