How to create a file using PHP
TAGS: PHP, Textfile


<?php
if (isset($_POST['doit']))  { 
$filename = $_POST['filename']; 
$stien = getcwd(); 
  $file = fopen($stien . "/" . $filename, 'w'); 
  fclose();	 
echo "Finished"; exit(); 
}
?> 

<HTML><BODY> 
<TABLE> 
<FORM METHOD='POST' ACTION=''> 
<TR> 
<TD>Give your file a name, <BR/>remember extension (.txt)</TD> 
<TD><INPUT TYPE='text' NAME='filename'></TD> 
</TR> 
<TR> 
<TD>Click here to create file: </TD> 
<TD><INPUT TYPE='submit' NAME='doit' VALUE='Create textfile'></TD> 
</TR></FORM> 
</TABLE> 
</BODY></HTML> 


This is a very simple example on how to create an empty textfile. .. or any flatfile. Simply put the above code into a .php file and call it from you webserver.