Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用phpexcel保存到临时文件_Php_Excel_Phpexcel - Fatal编程技术网

使用phpexcel保存到临时文件

使用phpexcel保存到临时文件,php,excel,phpexcel,Php,Excel,Phpexcel,我必须将excel保存在临时文件中,但我不知道如何保存 最初我是这样保存excel文件的 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="Autolarte.xlsx"'); header('Cache-Control: max-age=0'); header('C

我必须将excel保存在临时文件中,但我不知道如何保存

最初我是这样保存excel文件的

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Autolarte.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 
header ('Cache-Control: cache, must-revalidate'); 
header ('Pragma: public'); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
现在我想创建一个包含excel文件内容的临时文件

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Autolarte.xlsx"');
header('Cache-Control: max-age=0');
header('Cache-Control: max-age=1');
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 
header ('Cache-Control: cache, must-revalidate'); 
header ('Pragma: public'); 
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
我有这个例子,但因为我不知道excel的内容是什么变量,所以在我的例子中没有实现

$temp = tmpfile();
fwrite($temp, "writing in the temporary file");
fseek($temp, 0);
echo fread($temp, 1024);
fclose($temp);
现在我需要的是我的临时文件,我想把临时文件的路径和名称放在addfile中,以便将excel添加到zip中

$zipname = 'file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
$zip->addFile('/path/to/index.txt', 'newname.txt');
$zip->addFromString("testfilephp.txt", "#1 This is a test string added as  testfilephp.txt.\n");
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
exit;
save()
命令保存到文件,但您使用的是
php://output
作为文件名立即获取直接输出。只要改变它

$tempfile = tempnam();
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save($tempfile);

不要忘记在删除文件之后使用
unlink()

警告:strtolower()希望参数1是字符串,在/home1/autolart/public\u html/app/webroot/descargas/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php中给出的资源在第189行
警告:file\u exists()希望参数1是有效路径,第228行的/home1/autolart/public_html/app/webroot/descargas/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php中提供的资源,第232行的/home1/autolart/public_html/app/webroot/descargas/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php中提供的资源,第233行的/home1/autolart/public_html/app/webroot/descargas/PHPExcel-1.8/Classes/PHPExcel/Writer/Excel2007.php中给出的资源消息来自库,当函数被误用时会显示此消息