?
Solved

Writing files to a local disk

Posted on 2012-03-27
9
Medium Priority
?
1,539 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:ZumbaJr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 17

Expert Comment

by:Chris Harte
ID: 37771150
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
 

Author Comment

by:ZumbaJr
ID: 37771171
"c:\\teste\\image.jpg";

Sorry MunterMan, it does not works. Same "can't open file for write";
0
 
LVL 17

Expert Comment

by:Chris Harte
ID: 37771201
Include the line

ini_set('display_errors', 'on');  

at the top to give a better error message.
0
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
LVL 22

Expert Comment

by:Kim Walker
ID: 37771207
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
 

Author Comment

by:ZumbaJr
ID: 37771234
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
 
LVL 17

Accepted Solution

by:
Chris Harte earned 1500 total points
ID: 37771250
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
 
LVL 22

Expert Comment

by:Kim Walker
ID: 37771251
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
 

Author Closing Comment

by:ZumbaJr
ID: 37771309
I'll resolve it with javascript. Thanks very much.
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 37771389
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question