php


Safari SSL Can't download CSV


I have problem with safari when try download CSV while my website are using SSL.
When download CSV, Safari return an error: "Zero kb of 4KB. The connection was lost".
Then I click download again, safari download file successfully but contents of CSV are HTML code
Below are class download CSV, I'm using CodeIgniter 3 and safari 10.0.3 , Please help me, sorry for my bad English.
<?php
class Exportcsv {
var $data = array();
function addRow($data) {
$this->data[] = $data;
}
function pushFile($file_name) {
$this->saveFile($file_name, $this->data);
}
function saveFile($filename, $data) {
$filename = TMP_FOLDER . $filename;
$fp = fopen($filename, 'w');
foreach ($data as $row) {
fputcsv($fp, $row);
}
fclose($fp);
}
function downloadFile($fileName, $remove = true, $isEncoded = true) {
$userInfo = getLoggedUserInfo();
if ($userInfo->password_protected) {
$this->zip($fileName);
} else {
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header('Content-Type: text/csv;charset=UTF-8');
header(sprintf('Content-Disposition: attachment; filename="%s"', $fileName));
header('Content-Length: ' . filesize(TMP_FOLDER . $fileName));
$fileName = TMP_FOLDER . $fileName;
$fileContent = file_get_contents($fileName);
if ($remove) {
unlink($fileName);
}
ob_clean();
if ($isEncoded) {
echo mb_convert_encoding($fileContent, 'UTF-16LE', 'UTF-8');
} else {
echo $fileContent;
}
flush();
}
die;
}
function zip($fileName) {
$zip = new ZipArchive;
$destination = TMP_FOLDER;
$userInfo = getLoggedUserInfo();
$zip_name = $fileName;
rename($destination . $fileName, $destination . $zip_name);
$outfile = $destination . $zip_name . ".zip";
if ($zip->open(str_replace("//", "/", "{$outfile}"), ZipArchive::CREATE)) {
$zip->addFile($destination . $zip_name, str_replace(array("../", "./"), NULL, $zip_name));
$zip->close();
}
$password = decrypt(ENCRYPTION_KEY, $userInfo->protect_export);
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename={$zip_name}.zip");
shell_exec("zip -j -P {$password} {$destination}{$zip_name}.zip {$destination}{$zip_name}");
readfile($outfile);
#unlink($outfile);
#unlink($destination . $zip_name);
die;
}
}
?>

Related Links

Laravel Eloquent query unexpected result
PHP or htaccess - allow external server to check if file exists
How to set values in the select dropdown box?
Getting Controller does not exist after moving my controller to sub folder in laravel 5
Mysqli Count Two Data Type in one query
Invalid argument key “nameOfTheArgument” found symfony3 (Extending an abstract service)
Codecademy Functions, Part I PHP [duplicate]
Failed opening required '../vendor/autoload.php'
Compare between Two dates in php [duplicate]
Altering another document in Doctrine ODM PreUpdate event
FB access token is empty without any FB exception thrown from PHP SDK v5
Stream a PDF file in Laravel 5.2
BroadcastOn not firing in laravel 5.3?
How to execute a Symfony command as cron job?
use laravel Authentication in pure php scripts
show the data from complex json data in php

Categories

HOME
protocol-buffers
exchange-server
scroll
compilation
hid
command-prompt
mongoid
liferay-7
azure-data-lake
javafx-8
timber
global-variables
web-deployment
rpmbuild
bazaar
clr
yii2-basic-app
workday
bsd
coreldraw
altium-designer
stackexchange.redis
candlestick-chart
pyopencl
spreadsheetgear
running-object-table
onchange
amazon-iam
dotcms
epplus
microsoft-certifications
android-collapsingtoolbar
ms-media-foundation
custom-keyboard
gnu-classpath
directfb
uivisualeffectview
elastica
right-click
pyttsx
oracle-bmcs
flume-twitter
jenkins-slave
absolute
tinyioc
ol3-google-maps
solr-query-syntax
sonatype
deedle
bilinear-interpolation
dpkg
urbit
cortana
phpquery
arbre
replicaset
domino-designer-eclipse
org-babel
relational-model
inputbox
jquery-mobile-flipswitch
rpg
accessory
distributed-r
xulrunner
map
progress-db
san
yii-booster
jquery-transit
codahale-metrics
node.js-stream
multiple-dispatch
pcspim
prefuse
groovy-console
botnet
tablet-pc
jquery-1.4
photo-management
gaelyk
aptitude
3-tier
principles
resharper-5.0
zend-test
mysqli-multi-query
bucket
fxruby
rendering-engine

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App