Page 1 of 1

Creating A New File With PHP?

Posted: Thu Jul 10, 2003 10:13 pm
by Mr. Tech
I did search but too many results...

What my question is is how do I create a new file with php?

You enter the name of the file and what directory you want it to be saved in. I couldn't find anything here except fo a way to create a file with a .tmp file extension:

http://au2.php.net/manual/en/ref.filesystem.php

Thanks

Posted: Thu Jul 10, 2003 10:22 pm
by bionicdonkey
fopen() will create a file when used with w, w+, a, a+ parameter. e.g.

Code: Select all

<?
fopen("file.txt", "w");
?>
this will "Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it."

Posted: Thu Jul 10, 2003 10:36 pm
by macewan
http://au2.php.net/manual/en/function.fopen.php

Code: Select all

<?php
$newfile = fopen("data.txt", "a+");
fwrite($newfile, "This is a new file.");
fclose($newfile);
echo "All done";
?>