Creating A New File With PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mr. Tech
Forum Contributor
Posts: 205
Joined: Tue Feb 11, 2003 4:18 pm
Location: Australia

Creating A New File With PHP?

Post 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
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post 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."
macewan
Forum Commoner
Posts: 97
Joined: Mon Jul 07, 2003 8:27 pm

Post 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";
?>
Post Reply