Jump to content

Password Protect Excel or CSV File


stevesimo

Recommended Posts

Hi, my client has asked me to generate a CSV file or Excel file which is straight forward enough to do.  The complication is that they have asked if the file can be password protected.  Does anyone know how I could achieve this.  Is it actually possible to do this with PHP? 

 

Any advice on this subject would be appreciated.

 

Steve  :)

Link to comment
https://forums.phpfreaks.com/topic/132682-password-protect-excel-or-csv-file/
Share on other sites

Hi, my client has asked me to generate a CSV file or Excel file which is straight forward enough to do.  The complication is that they have asked if the file can be password protected.  Does anyone know how I could achieve this.  Is it actually possible to do this with PHP?

About the only way to password protect a text file such as a CSV would be to zip it up in a password-protected zip.

 

If you want to write the data to an Excel file, that can be password-protected.

This can also be done with PHP, but I'm not going to write [all] the code for you.

 

<?php
/** User Check / Login Code / Password Check **/

if( file_exist($_GET['file']) ) {
  header('Content-Length: '.filesize($_GET['file']);
  header("Content-Disposition: attachment; filename=\"{$_GET['file']}\"");
  header('Content-type: application/vnd.ms-excel');
  readfile($_GET['file']);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.