Writing files to a local disk

Hi Experts, I'm trying to write to a local disk using fwrite function but the script died. There's folder write/modify/total control permission to everyone.

the script:

               <?php
            $inputFilename = "image.jpg";
            $outputFilename = "c:\teste\image.jpg";
            $finput = fopen($inputFilename, "rb") or die ("can't open file for read");
            $foutput = fopen($outputFilename, "wb") or die ("can't open file for write");
            while(!feof($finput)) {
                  $contents = fread($finput, $buflen);
                  fwrite($foutput, $contents);
            }
            fclose($finput);
            fclose($foutput);
                ?>

returns: "can't open file for write"

Any idea?
Thanks in advance
Zumba
ZumbaJrAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Chris HarteConnect With a Mentor ThaumaturgeCommented:
Php is a server side technology. fopen only works on the local file system of the server. If you have the server running locally you can save to your machine, but it will only work on the machine that php is running on.
0
 
Chris HarteThaumaturgeCommented:
From the php manual 'On the Windows platform, be careful to escape any backslashes used in the path to the file, or use forward slashes.'

$outputFilename = "c:\\teste\\image.jpg";

Open in new window

0
 
ZumbaJrAuthor Commented:
"c:\\teste\\image.jpg";

Sorry MunterMan, it does not works. Same "can't open file for write";
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Chris HarteThaumaturgeCommented:
Include the line

ini_set('display_errors', 'on');  

at the top to give a better error message.
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
Are you trying to read and write to the same file? They both have the same file name. The read file will be in the same directory as the php file. Is the php file in the c:\teste directory, too?
0
 
ZumbaJrAuthor Commented:
MunterMan, it returns:

Warning: fopen(c:\\teste\\cabecalho4.jpg) [function.fopen]: failed to open stream: Permission denied in /vhosts/www.crcpr.org.br/html/new/admin/installFile.php on line 19
can't open file for write

If a specify a target name like "image.jpg" it works but the file was saved on the server, not on a local disk.
0
 
Kim WalkerWeb Programmer/TechnicianCommented:
If the script is running on a server, a local disk would be a disk on the server. Are you trying to save to a disk on a remote terminal?
0
 
ZumbaJrAuthor Commented:
I'll resolve it with javascript. Thanks very much.
0
 
gr8gonzoConsultantCommented:
Actually, you can't use any standard browser functionality to programmatically save a file to the client's computer. Javascript is client-side, but it will not allow you to do this. You could use a client-side program that plugs into the browser, like a Java applet or an ActiveX control.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.