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

Can't load image from MySQL database with PHP
Getting two different tables using SQL SELECT in one function width PDO
Submit Basic Form Using jQuery Ajax
Retrieving response after posting data using PHP Curl
PHP parse ini file that includes variables
Supports transactions, row-level locking, and foreign keys errorno 150
Wordpress directing to Posts page (edit.php) instead of saving post
MYSQL - Error Code :- 1241 “Operand should contain 1 column(s) ”
Singleton in constructor
HHVM - imagettftext(): “No such file or directory”
Yii - How to Show Value of Array in CGridView?
same script and software throws exception on windows
Undefined variable in actionblock template
MySQL - How can I/workaround ordering by the result of a group function
Create SEO-friendly URL from php using htaccess
Php - allow spaces in rewriteRule

Categories

HOME
entity-framework
user-interface
d3.js
compilation
ews
apk
gallery
ui-automation
static-analysis
kurento
yahoo
alljoyn
tiff
responsivevoice
mahout-recommender
android-custom-view
tableview
fido-u2f
batch-rename
pymongo
password-generator
morris.js
ibm-connections
fusion
social-networking
amazon-iam
infopath2010
identify
praat
grails-spring-security
jacoco-maven-plugin
haar-classifier
fluid-mac-app-engine
latexml
morphline
doctrine-extensions
daz3d
directwrite
icecast
brightscript
uiautomatorviewer
non-linear-regression
lightning-workbench
spring.net
gtk#
word-2007
stateless-session-bean
alertify
mechanicalturk
bigdecimal
gcloud-node
mathml
qpixmap
static-methods
ajaxmin
maximize
timestamping
in-app-billing
dnx50
sqlbase
360-degrees
domino-designer-eclipse
wicked-gem
gflags
mxe
nsmutabledata
sql-processor
phonegap-facebook-plugin
dos2unix
famo.us
datagridcomboboxcolumn
multivariate-testing
forceclose
boinc
yii-booster
rikulo
oscilloscope
proc-open
simplecov
cakeyframeanimation
mkannotation
wcf-callbacks
acpi
motodev-studio
server-variables
filelock
css-friendly
jmenu
3des
activestate
tabbarcontroller
eventaggregator
yahoo-maps
source-code-protection
.net-client-profile
subtext
downloadfile

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