ZumbaJr
asked on
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
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
ASKER
"c:\\teste\\image.jpg";
Sorry MunterMan, it does not works. Same "can't open file for write";
Sorry MunterMan, it does not works. Same "can't open file for write";
Include the line
ini_set('display_errors', 'on');
at the top to give a better error message.
ini_set('display_errors', 'on');
at the top to give a better error message.
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?
ASKER
MunterMan, it returns:
Warning: fopen(c:\\teste\\cabecalho 4.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.
Warning: fopen(c:\\teste\\cabecalho
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
ASKER
I'll resolve it with javascript. Thanks very much.
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.
Open in new window