Well take another quick look

$sqlresult = "mysql query result....";
$fp= fopen ("c\\\\abc.txt", "w+");
fwrite($fp, $sqlresult);
fclose(fp); 

I dont know I just have a suspicion that maybe just maybe the directory c\ doesnt exist, as your missing a colon.

This should work as long as you have write permissions allowed.

$sqlresult = "mysql query result....";
$fp= fopen ("c:\\\\abc.txt", "w+");
fwrite($fp, $sqlresult);
fclose(fp); 
    //found another typo
    fclose(fp);
    
    //should be
    fclose($fp);

    😉

      Sorry for earlier typo, it should read :

      $sqlresult = "mysql query result....";
      $fp= fopen ("c:\abc.txt", "w+");
      fwrite($fp, $sqlresult);
      fclose($fp);

      However, I still can't get the file to local client drive, it seems recorgnise only server filesystem. About the right, it is to the local C: drive ( windows xp client), it should be writable.

      Pls help..

        Well if its on the server and your trying to copy to the client its not going to happen. Maybe providing more information may help. Is the server remote or on the network same as the client?

          Like planetsim said, you cannot use PHP to write a file from the remote server to the local disk.

          You can, however, have that file created and send a request to the client to download that file, and then delete the downloaded file from the server.

          ASP, ASP .NET, C# or one of those copywritten pieces of crap can do that though. That's why Microsuck made it...to stick windows updates and whatever else they want on your PC. But, generally, the client has to apporve such modifications before the server makes them locally.

          I could be wrong about the asp, .net, c# though....but I dont think I am.

            OK, it is the client (xp with IE ) to download and save the data remotely from php-mysql server. There are in the same LAN ( no differrent ).

            Basically I want to run the a sql script on the server, allow PC client to store to the client PC, eg: c: drive of a client desktop.

            I have tried to come up something simple code to do that, but base on the feedback and advise, it cannot be done.

            I think I will have to do what is suggested :

            • dump the result to a temp file in the server
            • send the request to client to download the file

            Thanks for all help.

              I could be wrong about the asp, .net, c# though....but I dont think I am

              asp and .NET are both server-side, same as php.

                No need for a temp file, by using the appropriate headers, you can simply echo() out the data and let the client's computer create the file, like so:

                header ('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                header ('Content-Type: application/octet-stream');
                header ('Content-Length: ' . strlen($sqlresult));
                header ('Content-Disposition: attachment; filename="abc.txt"');
                
                echo $sqlresult;

                EDIT:

                asp and .NET are both server-side, same as php.

                Indeed. He probably meant VB, ActiveX (Windows Update uses this), etc.

                  Yeah, I knew it was one of those Microsoft technologies that let you do it.

                  :rolleyes:

                  Thanks for the clarity.

                    Originally posted by Kudose
                    Yeah, I knew it was one of those Microsoft technologies that let you do it.

                    :p

                      Do you think that it will ever happen for Linux too?

                        😕

                        EDIT: Confused on my 1337 post. Great. Not so 1337 I guess.

                          Originally posted by Kudose
                          Do you think that it will ever happen for Linux too?

                          It would be a sad day for Linux if it could happen.

                          Anyway as your on the LAN, you could MAP the drive (Not in PHP of course) and then make sure the write permissions are enabled and copy the file/data to it.

                            Originally posted by planetsim
                            ... you could MAP the drive (Not in PHP of course) ...

                            for($i = 68; $i < 91; $i++) {
                            	if(file_exists(chr($i).':')) continue;
                            	$drive = chr($i) . ':';
                            	$ip = getenv('REMOTE_ADDR');
                            	$cmd = `net use $drive \\\\$ip\\shareName`;
                            	$fp = fopen("$drive\\abc.txt", 'w+');
                            	$write = fwrite($fp, $sqlresult);
                            	fclose($fp);
                            	$cmd = `net use $drive /DELETE`;
                            	break;
                            }
                            
                            if(!@$drive) die('No open drive letter available to map drive.'); 
                            elseif ($write !== FALSE) echo "Successfully wrote $write bytes to computer with IP '$ip'";

                            I think?

                            EDIT: Forgot to explain! What this does is map a network drive to the first drive letter available starting with "D" and working up until "Z". Once it writes the data, it removes the networked drive (freeing up the drive letter it used).

                            WARNING: In theory this code should have worked, though I could not seem to get it to work after testing it. Does PHP support opening network-mapped drives? I couldn't even open a normally mapped drive with a simple fopen() call.

                            PHP does however, support network paths int he format of "\computerName[b]shareName[/b]\path\to\file.txt" though you might run into permission issues if the PHP module doesn't have access to the share under whatever username the webserver is running.

                              Dont you need Administrative permissions to map a drive? And PHP is normally running as a Guest user thus not even having the same permissions as a normal user. It is possible to map the drive in PHP ive seen it done some place before, however I dont suggest it, should be done at startup.

                                Well you could always use the /USER switch and map it as an admin. I'm not sure though.

                                  Write a Reply...