<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Problem with Excel Reports]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=5487&amp;type=atom" />
	<updated>2015-01-23T11:23:42Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=5487</id>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22304#p22304" />
			<content type="html"><![CDATA[<p>Just choose a define(&#039;XXXX&#039;,&#039;yyyy&#039;) in the calling script or one that already exists in FA and exit in the called script if it does not exist.</p><p>Sharing it in the public domain will help get rid of such vulnerabilities rather than live with &quot;security thru obscurity&quot;.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-01-23T11:23:42Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22304#p22304</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22303#p22303" />
			<content type="html"><![CDATA[<p>Hi apmuthu, that was the reason of my hesitation to share publicly the mod <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />Although there is a check for legal characters and one has to know the filename in order to be able to download it.<br />But obviously, I have to work more on that issue and will be updating the file to include more security.</p><p>carmelo</p>]]></content>
			<author>
				<name><![CDATA[carmelr]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=13862</uri>
			</author>
			<updated>2015-01-23T10:45:37Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22303#p22303</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22302#p22302" />
			<content type="html"><![CDATA[<p>Thanks @carmelr: way to go! Now look at the security implications of anyone having a go at the excel file maker script xlssend.php! Have a check for something to indicate that the user is logged in.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-01-23T10:00:22Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22302#p22302</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22299#p22299" />
			<content type="html"><![CDATA[<p>Here is what I did:</p><p>I created a file in fa/reporting called xlssend.php containing the following code:</p><div class="codebox"><pre><code>&lt;?php
$filename = htmlspecialchars($_GET[&#039;fn&#039;]);
$unique = htmlspecialchars($_GET[&#039;un&#039;]);
    header(&quot;Content-type: application/vnd.ms-excel&quot;);
    header(&quot;Content-Disposition: attachment; filename=&#039;$filename&#039;&quot; );
    header(&quot;Expires: 0&quot;);
    header(&quot;Cache-Control: must-revalidate, post-check=0,pre-check=0&quot;);
    header(&quot;Pragma: public&quot;);
    echo file_get_contents($unique);
?&gt;</code></pre></div><p>Then I modified the file FA/reporting/prn_redirect.php as follows:<br /></p><div class="codebox"><pre><code>if (isset($_GET[&#039;xls&#039;]))
{   
    $filename = $_GET[&#039;filename&#039;];
    $unique_name = preg_replace(&#039;/[^0-9a-z.]/i&#039;, &#039;&#039;, $_GET[&#039;unique&#039;]);
    $path =  company_path(). &#039;/pdf_files/&#039;;
//      header(&quot;Content-type: application/vnd.ms-excel&quot;);
//    header(&quot;Content-Disposition: attachment; filename=&#039;$filename&#039;&quot; );
//    header(&quot;Expires: 0&quot;);
//    header(&quot;Cache-Control: must-revalidate, post-check=0,pre-check=0&quot;);
//    header(&quot;Pragma: public&quot;);
//     echo file_get_contents($path.$unique_name);

    header(&quot;Location: xlssend.php?fn=$filename&amp;un=$path$unique_name&quot;); /* Redirect browser */ 
    exit();
}
elseif (isset($_GET[&#039;xml&#039;]))</code></pre></div><p>That&#039;s it. <br />Hope this will be useful for others.</p><p>Carmelo</p>]]></content>
			<author>
				<name><![CDATA[carmelr]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=13862</uri>
			</author>
			<updated>2015-01-23T08:15:35Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22299#p22299</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22290#p22290" />
			<content type="html"><![CDATA[<p>I too am unable to duplicate this error in a test environment in Debian Squeeze, Debian Wheezy and XAMPP v1.7.3 in WinXP SP3 / Win7 / LXDE on Debian 7 Desktop and IE 8 and FF33.</p><p>@carmelr can post the code and location of file include here and/or in the wiki for anyone encountering this problem.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-01-23T05:58:56Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22290#p22290</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22284#p22284" />
			<content type="html"><![CDATA[<p>Thanks Joe.<br />My fix is simply moving out that part of the file that downloads the .xls file. <br />According to my research there is something that is generating the spaces and for some reason they remain in the buffer.</p><p>Moving it out was the only way to get rid of them.</p><p>Carmelo</p>]]></content>
			<author>
				<name><![CDATA[carmelr]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=13862</uri>
			</author>
			<updated>2015-01-22T21:31:29Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22284#p22284</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22283#p22283" />
			<content type="html"><![CDATA[<p>Ok, carmelr,</p><p>I made a test here in my Environment and I got NO 4 spaces (0x20) in front of the file.</p><p>But if any other have the same problems as Carmelr, please Contact him.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2015-01-22T21:13:11Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22283#p22283</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22282#p22282" />
			<content type="html"><![CDATA[<p>P R O B L E M&nbsp; &nbsp;S O L V E D</p><p>I created another file that handles just the download of the excel file and passed the necessary parameters to it.</p><p>Now file downloads as it should and opens into Excel without a hitch.</p><p>I can share the code with anyone who is having similar problems.</p><p>Carmelo</p>]]></content>
			<author>
				<name><![CDATA[carmelr]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=13862</uri>
			</author>
			<updated>2015-01-22T21:02:00Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22282#p22282</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22280#p22280" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>apmuthu wrote:</cite><blockquote><p>Replace the line with:<br /></p><div class="codebox"><pre><code>$abc = &quot;Content-Disposition: attachment; filename=&#039;$filename&#039;&quot;;
header($abc);</code></pre></div></blockquote></div><p>Same results <img src="https://frontaccounting.com/punbb/img/smilies/sad.png" width="15" height="15" alt="sad" /></p><p>I have done more tests as follows:</p><p>I inserted an echo &#039;Testing&#039;; right after <br />If (isset(G_GET[&#039;xls&#039;]))<br />{</p><p>and tried again a report.<br />Now the file contains 4 spaces and Testing.<br />Then I added the following commands after the echo line and or before the first header line:</p><p>flush();<br />ob_clean();<br />ob_end_clean();</p><p>For all of the above, only the four spaces are prepended to the file.</p><p>I believe that somehow, these four spaces are being sent to the browser from a different part of the code and the flush or the ob_clean is not clearing these spaces from the buffers.</p><p>I come to this conclusion because the spaces were added even before the word &#039;Testing&#039; sent before the filename was created.</p>]]></content>
			<author>
				<name><![CDATA[carmelr]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=13862</uri>
			</author>
			<updated>2015-01-22T19:33:24Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22280#p22280</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22279#p22279" />
			<content type="html"><![CDATA[<p>Replace the line with:<br /></p><div class="codebox"><pre><code>$abc = &quot;Content-Disposition: attachment; filename=&#039;$filename&#039;&quot;;
header($abc);</code></pre></div>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-01-22T19:09:03Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22279#p22279</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22278#p22278" />
			<content type="html"><![CDATA[<p>Tried the quotes. Exactly the same results.</p><p><img src="https://frontaccounting.com/punbb/img/smilies/sad.png" width="15" height="15" alt="sad" /></p>]]></content>
			<author>
				<name><![CDATA[carmelr]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=13862</uri>
			</author>
			<updated>2015-01-22T18:27:15Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22278#p22278</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22277#p22277" />
			<content type="html"><![CDATA[<p>See my post of 4 seconds earlier than yours.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-01-22T18:23:38Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22277#p22277</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22276#p22276" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>apmuthu wrote:</cite><blockquote><p>This is a browser encoding issue. Try to set the browser encoding to Western and then to Unicode and see the difference. Also what platforms and browsers have you tried? What about a browser in Linux? The major ones - IE 8, FF24+, Chrome (I haven&#039;t tesed it), etc should have their own quirks for encoding settings. Also see if there are any line endings that may be dos instead of unix style in the scripts.</p><p>Also try to upload a good xls file to the server and download it back to see if there are any differences.</p></blockquote></div><p>Thanks apmuthu. I know that the file generated by FA on the Ubuntu server is good as when I downloaded it to my PC using Filezilla the file opened in Excel.<br />Also, when I created the few lines of php code in a separate file to download the file generated by FA through my browser, the file opened in Excel. <br />Then when I changed the code in FA to use the readfile function (like in the php file I created) the spaces appeared again.</p><p>For this reason I don&#039;t think that it is a browser problem or an encoding problem. I do think, though, that FA is setting something internally and is causing the 4 spaces to be prepended to the file.</p><p>Carmelo</p>]]></content>
			<author>
				<name><![CDATA[carmelr]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=13862</uri>
			</author>
			<updated>2015-01-22T18:20:42Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22276#p22276</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22275#p22275" />
			<content type="html"><![CDATA[<p>The only difference I find is that your $filename is quoted but the one in the code I posted is not!</p><p>Replace line 36 in reporting/prn_redirect.php<br /></p><div class="codebox"><pre><code>    header(&quot;Content-Disposition: attachment; filename=$filename&quot; );</code></pre></div><p>with<br /></p><div class="codebox"><pre><code>    header(&quot;Content-Disposition: attachment; filename=&#039;$filename&#039;&quot;);</code></pre></div><p>Or try swapping the single and double quotes in the replacement as well.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2015-01-22T18:20:38Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22275#p22275</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Problem with Excel Reports]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=22273#p22273" />
			<content type="html"><![CDATA[<p>Here&#039;s an update ....</p><p>So I created the following file on the server:<br /></p><div class="codebox"><pre><code>&lt;?php
    header(&#039;Content-type: application/vnd.ms-excel&#039;);
    header(&#039;Content-Disposition: attachment; filename=&quot;test.xls&quot;&#039;);
    readfile(&#039;pdf_files/test.xls&#039;);
?&gt;</code></pre></div><p>called the file and it works. It sends the file and opens in Excel</p><p>So I changed prn_redirect.php to be like the above and the spaces where still being added at the beginning of the file.<br />This means that there is some setting within FA that is causing this.</p><p>I did a lot of research online trying to find what is causing this problem, but I cannot find a solution.<br />Any assistance would be greatly appreciated.</p><p>TIA<br />Carmelo</p>]]></content>
			<author>
				<name><![CDATA[carmelr]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=13862</uri>
			</author>
			<updated>2015-01-22T18:07:06Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=22273#p22273</id>
		</entry>
</feed>
