issue with PHP spreadsheet reader - php

I am facing one issue with PHP spreadsheet reader https://github.com/nuovo/spreadsheet-reader , it is reading all formats file except .xlsx , in case of .xlsx script was not running
require($docroot.'/inc/filereader/excel_reader2.php');
require($docroot.'/inc/SpreadsheetReader.inc.php');
$Spreadsheet = new SpreadsheetReader("filepath");
When i am executing php script at my localhost, SpreadsheetReader reading .xlsx file and returning desired result, but when i am trying to run same code on some server then it is only executing for(.csv,.xls,.txt) but not for .xlsx.
I have already checked folder and file permissions for above issue at server.
What may be problem here?

An xlsx file is actually a zip file containing the spreadsheet payload as a set of xml files. This means that you need a php instance with the modules for zip and xml support loaded. The easiest way to check whether the correct modules are loaded is by executing phpinfo, like this
<?php
phpinfo();
?>
If the correct modules are not loaded you will probably have to contact your webhoster.

actually date_default_timezone_set('Asia/Calcutta'); is not set in spreadsheet reader and it is throwing exception

Related

Downloading 'blob' type file from database with PHP. Files are corrupted, unable to see the files' content

I try to use this code to download files from my database, however, when I try to open the file, I get following errors:
when downloading file type 'docx':
Word documents are stored with the type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' (not visible on the screenshot). I believe this is correct
I solved the bug when trying a bit different code:
Downloading jpg,doc,ppt files with php are corrupted

Cannot download using fpassthru

I'm trying to serve a file for download to a user, and I'm having trouble with fpassthru. The function I'm using to download a file is:
http://pastebin.com/eXDpgUqq
Note that the file is successfully created from a blob, and is in fact the file I want the user to download. The script exits successfully, and reports no errors, but the file is not downloaded. I can't for the life of me think what's wrong.
EDIT: I removed the error suppression from fopen(), but it still reports no error. Somehow the data in the output buffer is never being told to be downloaded by the browser.
I tried your code (without the blob part), and it worked fine. I can download a binary file. Based on my experience, here are something to check:
Has the file been completely saved before you initiate the reading? Check the return value of file_put_contents.
How large is the file? fpassthru reads the whole file into memory. If the file is too large, memory might be insufficient. Please refer to http://board.phpbuilder.com/showthread.php?10330609-RESOLVED-php-driven-file-download-using-fpassthru for more information.
Instead of downloading the file to local server (reading the whole file into server’s memory, and letting the client download the file from the server), you can create an SAS URL, and simply redirect the browser to the URL. Azure will take care of download automatically. You many want to refer to http://blogs.msdn.com/b/azureossds/archive/2015/05/12/generating-shared-access-signature-sas-using-php.aspx for a sample.
I was able to download the file by passing a stream obtained with the Azure API directly to fpassthru, without creating a file. Unfortunately, I can't show the code because it belongs to a project that I have finished working on and the code is no longer available to me.

PHPExcel Writer .xls file generates Excel error ... how can I change the extension to .csv?

I'm using a Wordpress plugin, wpdatatables, that uses PHPExcel to produce pdf, csv, and Excel file exports.
Anyway, when downloading an .xls file from my website, when I open it .. Excel gives me the error “The file format and extension of “blahblah.xls” don’t match. The file could be corrupted or unsafe. Unless you trust its source, don’t open it.”
Of course the file still opens fine, but I'd like to get rid of this error. One thing I noticed is the .CSV export is seemingly identical in all ways except the file extension, and opens without an error.
As someone who is not terribly familiar with PHP sadly, what direction should I look in to make PHPExcel produce .csv files only? Is there a specific function or directory in PHPExcel responsible for the Excel writer file output?

PHP not detecting XLS file as zip

I am using a library to read XLS files which internally uses PHP's zip_open() function. When creating the files locally and then uploading to my test server everything works fine. However, when I use the XLS files downloaded from a website (normal download via browser), it does not work, instead returning Error 19 meaning that the file is not seen as a zip file, which is incorrect. Excel opens the file without problems. If I re-save the file locally as an XLSX file and then upload it, I get the same error (in this instance the file is opened by the PHP's ZipArchive class). Any ideas what the reason could be? I checked that the files are not read only, possibly some Unix permissions could be set that are not displayed in Windows? (Doubt this, as the error code indicates that the file could be accessed, but could not be identified as XLS)
Using:
Apache under Windows (WAMP)
PHP 5.4.12
It seems I had misread a line of code, the zip check is only done to determine if the XLS file is an incorrectly named XLSX file. The problem with the XLS file is that it returns no sheets when parsing, I need to look into this still. I do not know why saving the XLS file as an XLSX file (using Excel) results in an incorrect ZIP archive though, but guessing it is related.

PHP Importing XML feed packed in a zip file

I want to automate the following:
Once a day my cronjob starts a PHP script that obtains a zipped XML file from an URL.
What would be the best way to handle this? Is there any way to directly read the XML file from within the zip file?
Right now, i'm just downloading the zipped file to the server and manually unpacking it later that day.
Any ideas? All suggestions are very much welcome.
You can use PHP's ZipArchive coupled with cURL to download and read the zip file.
Also, the ZipArchive class has a method called getStream which allows you to then use fread to access the contents without explicitly extracting the file.
The only problem I see if that the zip does have to be saved somewhere for PHP's library to read it. But, given you're already doing this, it shouldn't be an issue.
If you need an example, leave me a comment and I can write on up.
There is a collection of zip-related functions that can be used in PHP.
The problem with these is that it requires the compressed file to exist on the server (not just loaded from an external server somewhere using, for example, $file = file($url);).
If you were to save the file to your server then you could use $zip = zip_open($filename) and zip_read($zip) to process the zip file.

Categories