Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

code for php word document read only

Tags:

php

phpmyadmin

I have a php download script that allow user to download a word document file after downloading it is editable to user..i want to make file readonly to user

my code for download is:

//php code

// set headers`enter code here`
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mtype");
header("Content-Disposition: attachment; filename=\"$asfname\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $fsize);

// download
// @readfile($file_path);

$file = @fopen($file_path,"rb");
if ($file) {
  while(!feof($file)) {
    print(fread($file, 1024*8));
    flush();
    if (connection_status()!=0) {
      @fclose($file);
      die();
    }
  }
  @fclose($file);
}

thanx in advance Regards

like image 744
ahmer Avatar asked Aug 26 '26 10:08

ahmer


1 Answers

You can't. File attributes aren't sent with the download. The user downloads the file and owns it.

You can password-protect the document, but for that you have to edit it yourself. It is something that can hardly be done by PHP, although you could use the COM interface of Word from PHP on Windows... But that's not a path you want to go.

like image 198
GolezTrol Avatar answered Aug 28 '26 01:08

GolezTrol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!