I have a rather peculiar issue which appears to be related to excel formatting.
I have a Laravel 5.0 application and there's an Excel 97 (xlsx) download function using maatwebsite excel wrapper which works fine on my local MAMP platform as well on my CentOS VPS using a demo sub-domain on http:// connection.
But when I deployed the application to another folder and set it up to be served up by another subdomain on https:// connection on the same VPS, I get this error:
Excel cannot open this file.
The file format or file extension is not valid.
Verify that the file has not been corrupted and
that file extension matches the format of the file.
Any ideas what could be wrong?
Please note that exactly the same code works on the same server in a different folder under a different sub-domain on http:// protocol.
I even tried to create a basic file to eliminate data related issues but still get the same error, here's the test code I used:
Excel::create('Filename', function($excel) {
$excel->setTitle('Our new awesome title');
$excel->setCreator('Maatwebsite')
->setCompany('Maatwebsite');
$excel->setDescription('A demonstration to change the file properties');
})->export('xlsx');
Related
Im Using Joomla 3.8.1
I want to open a csv file on my pc, put data into it, then export back to pc.
I have tested the code and it is working in localhost server. I modified orders.php in components/com_virtuemart/views/orders
When I try to use on live server, it doesnt work for me. (code runs but file doesnt get written)
My question is do I need to remove any file protection security?
The code I'm using to open and put is following...
$file = fopen('d:\\WEBSITE\\files\\clientFile.csv', 'w');
fputcsv($file,$cust_ship);
Either the path doesn't exist or you don't have permissions to create/modify that file. Check the error message/logs.
I tried to save the file into a specific folder using the following code from a stack overflow thread PHPExcel Save a xls file to a specific folder
$objWriter->save(str_replace(__FILE__,'folder_path/filename.xlsx',__FILE__));
Since I am using yii 2 I tried this method
$objWriter->save(str_replace(__FILE__,Yii::getAlias('#web') .'/files/MyContacts.xlsx',__FILE__));
But it is not working the file still creates in the web (root folder). Is there a solution for the same ?
The error message i get is "Could not close zip file" (i am using a Windows Operating System)
Yii::getAlias('#web') returns URL of web application but for saving a file you need path of web application so try \Yii::getAlias('#webroot') instead.
so, I have a setup with apache2, php5, Mysql, etc... everything seems to work alright and I'm using default directory /var/www/html.
I can upload pdfs into directory /var/www/html/uploads, and also display the pdfs uploaded into directory in list of links by using scandir(php method).
I've also checked permissions on the directory, pdf files, and /etc/mime.types.
And ofc, the files are there too. I have also tried naming my pdf files with lower case without any special characters.
The error code is 404 Not found:The requested URL /var/www/html/uploads/cv.pdf was not found on this server. When I try to download the file, by right-clicking link and downloading, i just get a broken pdf that isnt readable. However, the pdf files seem perfectly fine, since when I scp them back to my local computer and read them they're not broken at all.
Any suggestions on why I may be experiencing this error?
All suggestions and help appreciated.
I'm using two computers (both connected to one network) and one of them has XAMPP. I'm trying to upload files to the one with XAMPP in it (the files are from the other computer). But I always end up having the 'No such file or directory' error even though I have the correct path. But when I use the path from the computer with XAMPP, even when I'm using the other computer, the system works just fine. Can anyone help me?
P.S. I'm using PHP copy() function because the file path is coming from an excel file.
Here's the part of my PHP code:
$original_file_name = objWorksheet->getCellByColumnAndRow(5,$i)->getValue();
// Example of the cell value: C:\Users\ComputerWithoutXAMPP\Desktop\scanned documents\SO 2010\#1.jpeg
$ext = pathinfo($original_file_name, PATHINFO_EXTENSION);
$file = time().substr(md5(microtime()),rand(0,26),5);
// UPLOAD THE FILE DECLARED IN EXCEL
copy($original_file_name, 'uploads/docs/'.$file.'.'.$ext);
You can use copy() to upload a file to another machine, or from another machine, but to access the remote machine, the appropriate argument to copy (source or dest) has to be a URL. The code you've posted is trying to copy the file to a local "uploads/docs/" directory, it's doesn't even appear to aware of another machine.
While what you're looking to do may be technically possible, I haven't the foggiest idea how you'd go about it: it seems rather Rube Goldberg to me. The ftp:// wrapper would probably work, if FTP is set up properly on the XAMPP server.
How big is the file you're trying to send? If it's small enough, you may have better luck either encoding and sending the content itself or uploading the file with curl to an upload-catching script on the XAMPP side
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.