Entry
How do i create a file using php??? I really need help! Please!!
How do i specify the encoding type of a file i create. ie. how to i save a utf-8 or utf-16 file from
How do i specify the encoding type of a file i create. ie. how to i save a utf-8 or utf-16 file from
Feb 17th, 2003 16:19
Marcin \"Mistral\" Kaskiewicz, your mother, george m,
Hello there.
Trully to say - haven't tested this solutin, but according to the PHP
manual function fopen opens file or URL (PHP 3, PHP 4 >= 4.0.0)
int fopen(string filename, string mode [, int use_include_path)
For to get a new file do use mode operator which, among others can be
(usefull for you) - still i am just copying&pasting php manual...:
mode may be any of the following:
(...)
'w' - 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.
'w+' - Open for reading and writing; 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.
'a' - Open for writing only; place the file pointer at the end of the
file. If the file does not exist, attempt to create it.
'a+' - Open for reading and writing; place the file pointer at the end
of the file. If the file does not exist, attempt to create it.
So choose the apropietary mode suiting your needs, and just think about
surely NOT existing filename... for to open with fopen(). Thus - having
not found this (thought of by you) filename and file - fopen will try
(having OFC permissions for creating file in the server catalog
strucuture pointe by you - but this is just another story) to create
file.
Simply then:
1. Make sure you point fopen to the location where it can create (and
save) file
2. Make an unique name for file (the one that does not exist - at least
at this location, otherwise fopen just open pointed file)
3. Use suitable for you modefor fopen.
edit the file, fwrite... and Voila ("Prosze bardzo" - in my native
language :)! :D
Full of hope for being helpfull.
Marcin Mistral Kaskiewicz