Hi,
What I want is this. Read a word document and write the document as a new file into a folder.
$fp = fopen($filename, 'r');
$output = fread($fp, filesize($filename));
//and then write file into a folder as a new file
How can I do this??
Thanks a lot!
How can I write file into a folder?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: How can I write file into a folder?
Have you looked in the manual at the filesystem functions? There are several different ways to copy a file.
http://www.php.net/manual/en/book.filesystem.php
http://www.php.net/manual/en/book.filesystem.php
(#10850)
Re: How can I write file into a folder?
Is there a reason not to use copy?
OK, actually it's pretty simple:
OK, actually it's pretty simple:
Code: Select all
$in = fopen('filename', 'r');
$out = fopen('filename2', 'w+');
// TODO: check if fopens() were successful
while (!feof($in)) {
$data = fread($in, 1024)
fwrite($out, $data);
}
fclose($in);
fclose($data);- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: How can I write file into a folder?
Or
I am sure there are several other ways to do it.
Code: Select all
$data= file_get_contents('filename');
file_put_contents('filename2', $data);(#10850)