OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

PHP outputting corrupt SXI file, PLEASE HELP [SOLVED!]

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
anonamos
General User
General User


Joined: 09 May 2005
Posts: 6

PostPosted: Thu Jun 16, 2005 2:26 pm    Post subject: PHP outputting corrupt SXI file, PLEASE HELP [SOLVED!] Reply with quote

hi, i've been working on this project for a long time... and i'm virtually at the last step but i really can't seem to get this part to work!

basically, i'm trying to automate the creation of a SXI file....

The user is supposed to be able to select songs, which i have the lyrics of in files.... and when the user selects all the songs it will generate an SXI file that will display all the lyrics on seperate pages....

the generation of the SXI file, i can do. However, the problem i'm having is outputting the file.

i read my sxi file and output it like this:
Code:

   $file=fopen(WebKeys::TEMP_FOLDER()."/$tempFilename","rb");
   fpassthru($file);


i've also tried using file_get_contents...

THE STRANGEST THING is that it works if i download the generated file directly. however if i go to the page that outputs the file with the code above, the file ends up corrupted.

try for yourselves:

generated and outputted (the no-ip site will be online depending on whether my pc is on or not):
http://anonamos.no-ip.org:1234/~amos/mcac/web/pptChooser.php

downloading the generated file directly:
http://anonamos.no-ip.org:1234/~amos/mcac/tmp/generated.sxi

please, any suggestions would be grrrrreatly appreciated.


Last edited by anonamos on Fri Jun 17, 2005 9:56 pm; edited 1 time in total
Back to top
View user's profile Send private message
DannyB
Moderator
Moderator


Joined: 02 Apr 2003
Posts: 3991
Location: Lawrence, Kansas, USA

PostPosted: Fri Jun 17, 2005 6:54 am    Post subject: Reply with quote

The files are different.
PHP generated file is 7803 bytes.
downloaded file is 7798 bytes.

Why is the php generated file five bytes larger? Could it be an issue where the file is being treated as "text", and for instance, a 0x0D is being changed into a 0x0D+0x0A? (i.e. a CR changed to a CR-LF pair? Or maybe an LF being changed to a CR-LF pair?)

When both files are renamed to ".zip" and unzipped, they both unzip to folders having identical contents (according to WinDiff), and identical sizes.

Obviously, the unzipped content must be different somehow, but I have not identified it yet. Sinze the zip files are different, the problem is obviously with the download process.

If you open the PHP generated file in impress, it does not work.
But if you take the PHP generated file (the broken one), rename it from ".sxi" to ".zip", then unzip it. Then re-zip it. Then re-name it from ".zip" back to ".sxi", then it will work. Therefore, the php download process somehow subtly corrupts the zip in a way that OOo does not like, but WinZip is still able to work with it.


Next, try using Linux's "wget" command on both URL's you provided.

When download the php-generated version, I see this....
Code:
danny@neo > wget http://anonamos.no-ip.org:1234/~amos/mcac/web/pptChooser.php
--09:49:46--  http://anonamos.no-ip.org:1234/%7Eamos/mcac/web/pptChooser.php
           => `pptChooser.php'
Resolving anonamos.no-ip.org... 65.93.157.161
Connecting to anonamos.no-ip.org|65.93.157.161|:1234... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7,803 [Content-Type: application/x-zip]

100%[====================================>] 7,803         34.38K/s

09:49:51 (34.27 KB/s) - `pptChooser.php' saved [7,803/7,803]


When downloading the "download" file using wget, I see this....
Code:
danny@neo > wget http://anonamos.no-ip.org:1234/~amos/mcac/tmp/generated.sxi
--09:50:13--  http://anonamos.no-ip.org:1234/%7Eamos/mcac/tmp/generated.sxi
           => `generated.sxi'
Resolving anonamos.no-ip.org... 65.93.157.161
Connecting to anonamos.no-ip.org|65.93.157.161|:1234... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7,798 [text/plain]

100%[====================================>] 7,798         31.69K/s

09:50:14 (31.58 KB/s) - `generated.sxi' saved [7,798/7,798]


Notice the difference....
php-generated says....
Length: 7,803 [Content-Type: application/x-zip]
download says....
Length: 7,798 [text/plain]

Both the length and the mimetype are different. What happens if in PHP, you try specifying a mimetype of text/plain instead of application/x-zip?
_________________
Want to make OOo Drawings like the colored flower design to the left?
Back to top
View user's profile Send private message
anonamos
General User
General User


Joined: 09 May 2005
Posts: 6

PostPosted: Fri Jun 17, 2005 1:37 pm    Post subject: Reply with quote

thanks for the help!

i've done those checks as well and noticed the size difference.... but i have tried using file comparison programs to see what the difference is... and i haven't been able to spot the problem.

i also suspect that the LF CR's may be getting corrupted... but i cannot spot it.

I've tried the text/plain content type.... and the results seem to be the same...

The reason I want to output the file to the user, instead of simply giving them the link, is that I want to remove it from the server immediately after the download. Is there any way i can do that WITHOUT outputting the file?

Thanks for your help, once again.
Back to top
View user's profile Send private message
JZA
OOo Advocate
OOo Advocate


Joined: 01 Feb 2003
Posts: 432
Location: Mexico

PostPosted: Fri Jun 17, 2005 1:50 pm    Post subject: Making SXW => SXI Reply with quote

There is an extension called PHP-DocWriter which output sxw files. This is a PHP class and I thnk it would be rather easy to just change it to generate SXI.

http://phpdocwriter.sf.net/
_________________
Alexandro Colorado
PPMC Apache OpenOffice
http://es.openoffice.org
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
anonamos
General User
General User


Joined: 09 May 2005
Posts: 6

PostPosted: Fri Jun 17, 2005 9:55 pm    Post subject: Reply with quote

after giving some thought to dannyB's research.... i've been WHAT could possibly be the reason that the 2 file sizes are different?

then i told myself to go on the safe side and set the content-type right before i output the file.

before, i was setting the content-type at the beginning of the file... processing the file and then outputting the file. Then i realized that PERHAPS there were some echo's along the way that corrupted the file!

now that i've moved it, it seems to be working fine! thanks a lot for both of your suggestions! i'm glad that i can finally move on to the next part of this project!

in the end, the snippet of code looked like this:

Code:

   //code above to process the sxi file....

   $file=fopen(WebKeys::TEMP_FOLDER()."/$tempFilename","rb");
   
   ini_set("zlib.output_compression", "Off");
   header("Content-type: Content-Type: text/plain"); 
   header("Content-disposition: attachment; filename=generated.sxi");
   
   fpassthru($file);
   fclose($file);


Thanks a lot, you guys have been a lot of help!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group