Problem with save file on server

Topics: User Forum
Mar 26, 2013 at 3:25 PM
Edited Mar 26, 2013 at 3:39 PM
Hi,

I have a problem with saving an excel file on the server

I try to modify the 01simple.php example :
<?php
/**
 * PHPExcel
 *
 * Copyright (C) 2006 - 2011 PHPExcel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category   PHPExcel
 * @package    PHPExcel
 * @copyright  Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
 * @version    ##VERSION##, ##DATE##
 */

/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', '1');
date_default_timezone_set('Europe/London');

/** PHPExcel */
require_once 'includes/outils/PHPExcel/Classes/PHPExcel.php';


// Create new PHPExcel object
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();

// Set properties
echo date('H:i:s') . " Set properties\n";
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
                             ->setLastModifiedBy("Maarten Balliauw")
                             ->setTitle("Office 2007 XLSX Test Document")
                             ->setSubject("Office 2007 XLSX Test Document")
                             ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
                             ->setKeywords("office 2007 openxml php")
                             ->setCategory("Test result file");


// Add some data
echo date('H:i:s') . " Add some data\n";
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Hello')
            ->setCellValue('B2', 'world!')
            ->setCellValue('C1', 'Hello')
            ->setCellValue('D2', 'world!');

// Miscellaneous glyphs, UTF-8
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A4', 'Miscellaneous glyphs')
            ->setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');

// Rename sheet
echo date('H:i:s') . " Rename sheet\n";
$objPHPExcel->getActiveSheet()->setTitle('Simple');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Save Excel 2007 file
echo date('H:i:s') . " Write to Excel2007 format\n";

 //!!!!!!!!!!!!!!!!!!!-------- I Change 'Excel2007' to 'Excel5' ------!!!!!!!!!!!!!!!!!!!!!!!!
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
 //!!!!!!!!!!!!!!!!!!!-------- I Change '.xlsx' to '.xls'              ------!!!!!!!!!!!!!!!!!!!!!!!!
$objWriter->save(str_replace('.php', '.xls', __FILE__));


// Echo memory peak usage
echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";

// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
but the created file is empty....

on my brower the result is :
Image

The file was created :
Image

have you an idea to resolve my problem ?

Thanks you in advance :)
Mar 27, 2013 at 9:53 AM
(I see the word 'Image' but not the images themselves)
The unmodified example work? No error messages (in a logfile if nothing appears on the screen)?
Mar 27, 2013 at 10:01 AM
Edited Mar 27, 2013 at 6:01 PM
thx for your answer :)

LWol wrote:
(I see the word 'Image' but not the images themselves)
In the first Image the result is :
08:47:34 Create new PHPExcel object 08:47:34 Set properties 08:47:34 Add some data 08:47:34 Rename sheet 08:47:34 Write to Excel2007 format ÐÏࡱá;þÿ þÿÿÿþÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ » ÌÑB°=Œ%r8X"1ܐCalibriàõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À àõÿ À à À “€ÿ’â8ÿÿÿÿÿÿÿÿÿÿÿÿ€€€€€€€€€ÀÀÀ€€€™™ÿ™3fÿÿÌÌÿÿffÿ€€fÌÌÌÿ€ÿÿÿÿÿÿ€€€€€ÿÌÿÌÿÿÌÿÌÿÿ™™Ìÿÿ™ÌÌ™ÿÿÌ™3fÿ3ÌÌ™ÌÿÌÿ™ÿfff™–––3f3™f333™3™3f33™333…USimpleÁÁgæ®üOHelloworld!Miscellaneous glyphs » ÌÑ*+‚€Áƒ„&ffffffæ?'ffffffæ?(è?)è?¡"dXX333333Ó?333333Ó?U}$ }$ }$ }$ }$ }$ }$ }$ }$ } $ } $ }$ }$ } $ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ }$ } $ }!!$ }""$ }##$ }$$$ }%%$ }&&$ }''$ }(($ }))$ }**$ }++$ },,$ }--$ }..$ }//$ }00$ }11$ }22$ }33$ }44$ }55$ }66$ }77$ }88$ }99$ }::$ };;$ }<<$ }==$ }>>$ }??$ }@@$ }AA$ }BB$ }CC$ }DD$ }EE$ }FF$ }GG$ }HH$ }II$ }JJ$ }KK$ }LL$ }MM$ }NN$ }OO$ }PP$ }QQ$ }RR$ }SS$ }TT$ }UU$ }VV$ }WW$ }XX$ }YY$ }ZZ$ }[[$ }\\$ }]]$ }^^$ }__$ }``$ }aa$ }bb$ }cc$ }dd$ }ee$ }ff$ }gg$ }hh$ }ii$ }jj$ }kk$ }ll$ }mm$ }nn$ }oo$ }pp$ }qq$ }rr$ }ss$ }tt$ }uu$ }vv$ }ww$ }xx$ }yy$ }zz$ }{{$ }||$ }}}$ }~~$ }$ }€€$ }$ }‚‚$ }ƒƒ$ }„„$ }……$ }††$ }‡‡$ }ˆˆ$ }‰‰$ }ŠŠ$ }‹‹$ }ŒŒ$ }$ }ŽŽ$ }$ }$ }‘‘$ }’’$ }““$ }””$ }••$ }––$ }——$ }˜˜$ }™™$ }šš$ }››$ }œœ$ }$ }žž$ }ŸŸ$ }  $ }¡¡$ }¢¢$ }££$ }€€$ }¥¥$ }ŠŠ$ }§§$ }šš$ }©©$ }ªª$ }««$ }¬¬$ }­­$ }®®$ }¯¯$ }°°$ }±±$ }²²$ }³³$ }ŽŽ$ }µµ$ }¶¶$ }··$ }žž$ }¹¹$ }ºº$ }»»$ }ŒŒ$ }œœ$ }ŸŸ$ }¿¿$ }ÀÀ$ }ÁÁ$ }ÂÂ$ }ÃÃ$ }ÄÄ$ }ÅÅ$ }ÆÆ$ }ÇÇ$ }ÈÈ$ }ÉÉ$ }ÊÊ$ }ËË$ }ÌÌ$ }ÍÍ$ }ÎÎ$ }ÏÏ$ }ÐÐ$ }ÑÑ$ }ÒÒ$ }ÓÓ$ }ÔÔ$ }ÕÕ$ }ÖÖ$ }××$ }ØØ$ }ÙÙ$ }ÚÚ$ }ÛÛ$ }ÜÜ$ }ÝÝ$ }ÞÞ$ }ßß$ }àà$ }áá$ }ââ$ }ãã$ }ää$ }åå$ }ææ$ }çç$ }èè$ }éé$ }êê$ }ëë$ }ìì$ }íí$ }îî$ }ïï$ }ðð$ }ññ$ }òò$ }óó$ }ôô$ }õõ$ }öö$ }÷÷$ }øø$ }ùù$ }úú$ }ûû$ }üü$ }ýý$ }þþ$ }ÿÿ$ ý ý ý ý ý >¶@ggÿÿÿÿÿ Root Entryÿÿÿÿÿÿÿÿ ÀF€m"ºÇ*΀m"ºÇ*ÎWorkbookÿÿÿÿÿÿÿÿÿÿÿÿ ÀF­ þÿÿÿþÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ08:47:35 Peak memory usage: 9 MB 08:47:35 Done writing file. 
LWol wrote:
The unmodified example work? No error messages (in a logfile if nothing appears on the screen)?
No because there is a problem with Excel 2007 (library or whatever) but i think with 'Excel5' it does it works easy normaly (a lot of example on the internet with 'Excel5') but not with me -_-'


edit : the second image is just the result in Excel (error message at the opening file), and next the file is empty (0 ko...)
Mar 27, 2013 at 5:21 PM
You have it on the screen (browser) using exactly the example?
Your Excel file is not in a file, but on the screen!
Can you test by giving to the save method, a simple filename (test.xls) with an absolute path for which you can be sure that php has the right to write?
Subsidiary question, your version of php?
Mar 27, 2013 at 6:00 PM
Edited Mar 27, 2013 at 6:02 PM
LWol wrote:
You have it on the screen (browser) using exactly the example?
Yes

LWol wrote:
Your Excel file is not in a file, but on the screen!
Yes, this is my problem, the excel file appear as an echo on PHP and it's not wrote on the .xls

LWol wrote:
Can you test by giving to the save method, a simple filename (test.xls) with an absolute path for which you can be sure that php has the right to write?
same result :/
I test with :
$objWriter->save('ddddd/toto.xls');

toto.xls is empty and i have the Excel file on my browser

LWol wrote:
Subsidiary question, your version of php?
5.2.9-1
Mar 28, 2013 at 9:59 AM
I found a temporary solution :
$objWriter = PHPExcel_IOFactory::createWriter($this, 'Excel5');
$objWriter->save($tmpFilename);
chmod($tmpFilename, 0777);
$excelOutput = ob_get_clean();
$fp = fopen($tmpFilename, 'w');
fwrite($fp, $excelOutput);
fclose($fp);        
I wrote manually in the file.... :/