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
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.

Link to comment
Share on other sites

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']);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.