PHPOffice / PHPExcel

ARCHIVED
Other
11.46k stars 4.2k forks source link

Extra line at top of generated file corrupts is corrupting file #1336

Closed mgnshawn closed 6 years ago

mgnshawn commented 6 years ago

I'm generating an .xls file but on my new server the output has a preceding new line at the top. I go into vim and delete this line and then the file renders fine. I have the exact same codebase, PHP, and Apache setup on my development machine and do not have this issue.

I've tried it with and without ob_end_clean(), with and without image banners. No matter what I've tried so far any .xls generated from the new server is download corrupt because of this new line at the top of the file.

The only difference in the output is the hex byte 0A at the start of the file.

There is nothing in the logs jumping out at me on this one. Any help is much appreciated.

PHP Version 7.0.22-0ubuntu0.16.04.1 Apache Version | Apache/2.4.18 (Ubuntu)

Loaded Modules | core mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate mod_dir mod_env mod_filter mod_headers mod_include mod_mime prefork mod_negotiation mod_php7 mod_rewrite mod_setenvif mod_socache_shmcb mod_ssl mod_status

Additional .ini files parsed | /etc/php/7.0/apache2/conf.d/10-mysqlnd.ini, /etc/php/7.0/apache2/conf.d/10-opcache.ini, /etc/php/7.0/apache2/conf.d/10-pdo.ini, /etc/php/7.0/apache2/conf.d/15-xml.ini, /etc/php/7.0/apache2/conf.d/20-calendar.ini, /etc/php/7.0/apache2/conf.d/20-ctype.ini, /etc/php/7.0/apache2/conf.d/20-curl.ini, /etc/php/7.0/apache2/conf.d/20-dom.ini, /etc/php/7.0/apache2/conf.d/20-exif.ini, /etc/php/7.0/apache2/conf.d/20-fileinfo.ini, /etc/php/7.0/apache2/conf.d/20-ftp.ini, /etc/php/7.0/apache2/conf.d/20-gd.ini, /etc/php/7.0/apache2/conf.d/20-gettext.ini, /etc/php/7.0/apache2/conf.d/20-iconv.ini, /etc/php/7.0/apache2/conf.d/20-intl.ini, /etc/php/7.0/apache2/conf.d/20-json.ini, /etc/php/7.0/apache2/conf.d/20-mbstring.ini, /etc/php/7.0/apache2/conf.d/20-memcached.ini, /etc/php/7.0/apache2/conf.d/20-mysqli.ini, /etc/php/7.0/apache2/conf.d/20-pdo_mysql.ini, /etc/php/7.0/apache2/conf.d/20-phar.ini, /etc/php/7.0/apache2/conf.d/20-posix.ini, /etc/php/7.0/apache2/conf.d/20-readline.ini, /etc/php/7.0/apache2/conf.d/20-shmop.ini, /etc/php/7.0/apache2/conf.d/20-simplexml.ini, /etc/php/7.0/apache2/conf.d/20-soap.ini, /etc/php/7.0/apache2/conf.d/20-sockets.ini, /etc/php/7.0/apache2/conf.d/20-sysvmsg.ini, /etc/php/7.0/apache2/conf.d/20-sysvsem.ini, /etc/php/7.0/apache2/conf.d/20-sysvshm.ini, /etc/php/7.0/apache2/conf.d/20-tokenizer.ini, /etc/php/7.0/apache2/conf.d/20-wddx.ini, /etc/php/7.0/apache2/conf.d/20-xmlreader.ini, /etc/php/7.0/apache2/conf.d/20-xmlwriter.ini, /etc/php/7.0/apache2/conf.d/20-xsl.ini, /etc/php/7.0/apache2/conf.d/20-zmq.ini selection_051 selection_053

mgnshawn commented 6 years ago

Solved! A non-display include file had a trailing LF after the closing tag. I found this quick command in a Google search which worked well in finding these: for f in `find . -type f`; do for t in head tail; do $t -1 $f |egrep '^[ ]*$' >/dev/null && echo "blank line at the $t of $f"; done; done