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).
Related
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!
I am writing a php extension for a library. I have a generic swig file to build wrappers for the library. This has been very successful so far on Python.
A user is trying to build the library for php and I am trying to help out. I generated the code using swig, and I can build the .dll extension using Visual Studio. The problem is getting it into php. When I build php_mylib.dll, it needs to find mylib.dll and it can't.
So I am trying to build via the command line a la:
http://blog.benoitblanchon.fr/build-php-extension-on-windows/
I have put all the files to be compiled and the libraries needed (i.e. mylib64.lib and mylib64.dll) in a folder called mylib in the C:\php-src\ext folder with all the other extension folders.
The problem is I that I can't get the config.w32 file to communicate the location of mylib. Here is my config.w32 file (pretty standard -- you can see that I copied it from the curl config.w32 file):
// $Id$
// vim:ft=javascript
ARG_ENABLE("mylib", "mylib support", "no");
if (PHP_MYLIB != "no") {
if (CHECK_LIB("mylib64.lib", "mylib", PHP_MYLIB) &&
CHECK_HEADER_ADD_INCLUDE("mylib_cpp.h", "CFLAGS_MYLIB")
) {
EXTENSION("mylib", "mylib_c_wrap.cpp", true);
AC_DEFINE('HAVE_MYLIB', 1, 'Have mylib library');
// TODO: check for curl_version_info
} else {
WARNING("mylib not enabled; libraries and headers not found");
}
}
When I run buildconf and then configure --disable-all --enable-cli --enable-mylib it always shoots me the 'libraries and headers not found' warning from the script.
On Unix systems (config.m4) there appears to be a PHP_ADD_LIBRARY_WITH_PATH macro but I don't see any equivalent for windows. It seems like this is what I need.
I have also tried adding the full path to mylib into the system's path but to no avail. It seems like there might be an environment variable somewhere in the PHP build cosmos that needs to be set to find external dependencies, but I can't find any information about this.
It would also be good to do all this as a Visual Studio project -- easier for Windows users the world over. I have not seen anything on the web that looks like this.
By the way, I have successfully phpized this library using the same swig+phpize procedure on Linux (I followed this guide for the php part:http://www.sitepoint.com/install-php-extensions-source/) and it works beautifully.
In most cases you can use this info to build a PECL extension https://wiki.php.net/internals/windows/stepbystepbuild#building_pecl_extensions . Your config.w32 looks ok, though please note that that when depending on some additional library, usually it should be ARG_WITH(...) for semantics. Your lib stuff can be then put into the deps dir as in the wiki.
Another way could be passing --with-extra-libs and --with-extra-includes to configure. Those have to contain paths to *.lib and *.h dirs respectively. When using a static lib, that should be it, otherwise you'll need to place the corresponding *.dll onto the %path% for the ext to work.
Hope this helps, otherwise you can also gain some attention on the PHP mailing lists or specifically on #winphp-dev at freenode.
Thanks.
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...
I use Excel Writer of Harish Chauhan to generate an excel (xls) file.
Then I use phpExcelReader 2 to read the file created by the Excel Writer class but have this error all the time :
The filename myXls.xls is not readable
I can open the "myXls.xls" file with MS Excel. But if I save the file with another name , it can be read successfully.
Try to explore the code, it seems that the error was given by :
if (substr($this->data, 0, 8) != IDENTIFIER_OLE) {
//echo 'Error';
$this->error = 1;
return false;
}
IDENTIFIER_OLE was defined :
define('IDENTIFIER_OLE', pack("CCCCCCCC",0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1));
I dont have any idea about how to fix it. Please help.
Thanks for your time!
The file generated by Harish Chauhan's ExcelWriter class is not an actual OLE BIFF .xls file, but a mix of HTML markup and some elements from SpreadSheetML, the XML format defined by Microsoft as an alternative to BIFF in Excel 2003. It never proved particularly popular; but the later versions of MS Excel itself can still read and write this format. MS Excel is also very forgiving about reading HTML markup, though the latest version will give you a notice informing you if a file format does not match its extension.
phpExcelReader 2 is written to read Excel BIFF files, therefore it is incapable of reading the non-OLE/non-BIFF files generated by Harish Chauhan's class.
If you want to write and read files in the correct format, then I suggest you use PHPExcel, or one of the many other PHP libraries that work with genuine Excel files.
I had the same problem. The task was to parse very old XLS file (Excel2). I could not find any library in PHP which works with such an old format.
So the solution was to make conversion with LibreOffice command line to XLSX (works to CSV also) and then parse it with any "moderner" Excel parser.
We got LibreOffice installed in our server and this is the command to convert:
libreoffice --headless --convert-to xlsx original_source.xls
or
libreoffice --headless --convert-to csv original_source.xls
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