How to protect excel file from being opened in php. i have created password protected zip file using
exec(zip -p file.zip /path);
but problem i faced here is when i tried to extract password protected zip in windows. i works fine in linux OS but not in windows.
Can anybody suggest me how to protect excel file with password in php either with zip method or directly password on excel file using PHP Code.
Did you try using the setEncryption method?
$dompdf->get_canvas()->get_cpdf()->setEncryption("pass", "pass");
The answer by Simone is very close.
Here is a working example with Laravel 5.4 and the Laravel DOMPDF wrapper by barryvdh:
$content = 'some html';
$dompdf = \App::make('dompdf.wrapper');
$dompdf->loadHTML($content)->setPaper('a4');
$dompdf->getDomPDF()->getCanvas()->get_cpdf()->setEncryption("pass", 'your_password');
If you are not using the barryvdh package, simply inspect your the dompdf library until you find the methods which retrieve the Canvas class and then the CPDFclass, which contains the setEncryption method.
Hope this helps!
Related
I'd like to know how can I copy a file from localhost to the remote server using the phpseclib library? Which functions within the library would achieve this?
Check this example. if you use the latest version of phpseclib you should use SOURCE_LOCAL_FILE const instead of NET_SFTP_LOCAL_FILE.
I am using ZendFramwork1, my local sever php 5.4. and with MongoDB .I have use function Zend_Pdf to draw PDF in my project. it's run well in my local server. but when i put code to sever that have same version PHP. Everything module is okay but for function print data to pdf is errors . I got message like PDF error: Can not open 'data/reports/myfile.pdf' file for writing. . Any one can help me . what's different between my local server and real sever ?
I am looking to see your reply soon.
thank
First off, chmod 777 is a hack and shouldn't really be used. If you're using apache, you are better off chown'ing the folder to the correct user.
I am using php class Spreadsheet_Excel_Reader , I am confused how to read password protected file through this class .
I give different permissions to file to read.BUt found no option in excel reader that I can read file through this library
If the whole file is password protected, then you can't: SEW does not read encrypted workbooks. You'll need to use COM or PUNO or Ilia Alshanetsky's Excel extension to the libXL library to do this (though check before buying libXL, as I'm not certain that it handles password protected files).
I have just now discovered that my hosting server does not support the ZIP class for PHP.
However, it has the Zlib installed and supported .
Is there any library / function / hack / class / that will let me handle ZIP files on such a server ?
Basically I want to create zip files. I am afraid my users will be scared of the GZ extension and i would like to serve them ZIP extension (that they will open normally on win systems) ?
(please do not tell me to change hosting - I already know I have to , but it will take time and the thing is quite urgent..)
UPDATE I . thanks to #Mark Baker - i was able to extract a file with the pclzip class and this simple code
<?php
include('pclzip.lib.php');
$archive = new PclZip('wp.zip');
$location = $_SERVER['DOCUMENT_ROOT'];
if ($archive->extract(PCLZIP_OPT_PATH, $location ,
PCLZIP_OPT_REMOVE_PATH, 'install/release') == 0) {
die("Error : ".$archive->errorInfo(true));
}
?>
(I just wanted to post the code here , it was too lng for comment , and I did not wanted to post another answer )
Still did not tested the creation, but if it works the same - then I really want to kiss the developers of that class ! :-)
Zlib doesn't help you create zip files.
As an alternative to your missing ZipArchive, you might take a look at the PCLZip library. This is pure PHP, so no need for additional extensions, and allows you to create zip files without ZipArchive.
I believe that on windows the extension only tells it what application to use to open it.
So you could just save it as something winzip will open, and then just rename it...
Slightly weird concept here... A client of ours wants data pushed to them over FTP/S
The idea is that we download one of our reports by downloading from a URL (a CSV File), then push this to the client over FTP/S. I know I can do this in bash scripts using wget & ftp - but need to add to this over a web interface so PHP is the best way forward.
As this is a background task I can extend time-outs etc.
I know also I can use fopen to download and save a file, then find it and upload it using the PHP FTP library. Just looking for a way to download using fopen, hold the data in memory to upload straight away.
Any help appreciated in advance!
To retrieve the data from the URL you have a few options. You say you want the data in memory only to push directly to the FTP host.
One approach (that I find the simplest to use, but lacking in terms of reliability and error handling) is file_get_contents()
Example:
$url = 'http://www.domain.com/csvfile';
$data = file_get_contents($url);
Now you have your csv data in $data, over to how to push this to an ftp server.
Again the simplest way to do this is to use the builtin stream wrappers as used in the get example above. (Note however that this requires PHP 4.3.0)
Simply build up the connection string like this.
$protocol = 'ftps';
$hostname = 'ftp.domain.com';
$username = 'user';
$password = 'password';
$directory = '/pub';
$filename = 'filename.csv';
$connectionString = sprintf("%s://%s:%s#%s%s/%s",
$protocol,$username,$hostname,
$password,$directory,
$filename);
file_put_contents($connectionString,$data);
Have a look at the ftp wrappers manual
If this does not work there are other options.
You could use curl to get the data and the FTP Extension to push it.
To avoid saving the file to disk and "to upload straight away" i.e. to start pushing to FTP as soon as the first chunk of Data is downloaded?
Try this:
http://www.php.net/manual/en/function.stream-copy-to-stream.php
You'll need an FTP server and client library which support resuming uploads