Page 1 of 1
PHP Append One File To Another
Posted: Fri Oct 26, 2007 2:42 pm
by jstorm13
Hello:
I have a php file, when it is executed I would like it to append one file to another.
Can anyone tell me the command for this. I think it might be possible to use the system
command and cat temp.txt >> file.txt but I can't seem to get the statement correct.
Can anyone help me out?
temp.txt file needs to be appended to file.txt and I want to do this inside my PHP code.
thanks,
Jason
Posted: Fri Oct 26, 2007 3:36 pm
by RobertGonzalez
Can you use the filesystem functions in this situation?
Posted: Fri Oct 26, 2007 3:44 pm
by jstorm13
I tried something like
but it did not work. the files will change on a daily basis. the system command would work
if the files were static.
Code: Select all
system("cat temp.txt >> main.txt");
since the files change daily, that is why i am looking for a system solution or something, but
i think the system command will only accept two " " which prevents me from using $temp or
something like that.
thanks for the help.
Posted: Fri Oct 26, 2007 4:00 pm
by RobertGonzalez
What I am saying is using something like
file(),
fopen(),
fputs(), etc.
Posted: Fri Oct 26, 2007 4:08 pm
by jstorm13
yes, i can use those, so you think that is the most simple way to do it?
open both files, one for reading and one for append
use a while statement not end of file and fgets, then fputs??
i was thinking there might be a one line command to do this, but if not, i can just do it
the other way.
thanks
Posted: Fri Oct 26, 2007 4:25 pm
by ASDen
There must be i used to do it in Dos using copy command from several files to one file
so there must be a Linux alternative just search for something similar to Dos approach
Posted: Fri Oct 26, 2007 5:29 pm
by jstorm13
I just did it another way.
Code: Select all
fputs($fp, "cat ".$temp." >> ".$main);
and
system(". batch.bat &");
i just thought there might be a one line with system() instead of a few.
thanks guys..