Move file or directory to C:\\Windows using PHP - XAMPP

913 views Asked by At

I am stuck in a script. I am developing a php based application and client can use it offline using XAMPP server after installation. I want to create a file called lic.txt during installation and i have managed to create it as well..

The only problem i am facing is i am unable to move the file into C:\Windows Folder and i want to move it there only. I am able to move file anywhere within XAMPP folder which is installed at C:\XAMPP

Code is something like this :

  <?php
    $filename = 'lic.txt';
$data = 'License Registered Successfully';
$newlocation = 'C:\\Windows\\lic.txt';
    $fh = fopen($filename, 'w'); 
     fwrite($fh, $data); 
     fclose($fh);
    rename($filename, $newlocation);

    ?>

When i run the file it is giving me the error

Warning: rename(lic.txt,C:\Windows\lic.txt): Access is denied. (code: 5) in C:\xampp\htdocs\latest\fwrite.php on line 9

I know this is because insufficient privileges to the folder but i have searched the whole web but couldn't find any solution. Is there anyone who can help me out to resolve the issue.

Thanks...

1

There are 1 answers

4
datasage On

To begin with, that is not the kind of application PHP is designed for. There are much better choices.

In order to read or write to the windows directory, you need to run XMAPP with administrator privileges. Which will probably make it difficult to deploy this to any customer.