Solved

Writing files to a local disk

Posted on 2012-03-27
9
1,360 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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 16

Expert Comment

by:Chris Harte
Comment Utility
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
Comment Utility
"c:\\teste\\image.jpg";

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

Expert Comment

by:Chris Harte
Comment Utility
Include the line

ini_set('display_errors', 'on');  

at the top to give a better error message.
0
 
LVL 21

Expert Comment

by:Kim Walker
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:ZumbaJr
Comment Utility
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 16

Accepted Solution

by:
Chris Harte earned 500 total points
Comment Utility
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 21

Expert Comment

by:Kim Walker
Comment Utility
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
Comment Utility
I'll resolve it with javascript. Thanks very much.
0
 
LVL 34

Expert Comment

by:gr8gonzo
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Mysqli Query 5 40
Link SQL table to Webpage 9 37
sql sentence 2 10
php connect() failed error 25 12
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now