|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello to everybody,
I have this problem with downloading files via PHP. For illustration - I am using this fragment of code: <?php header("Content-type: $contenttype; name=\"$outputfilename\""); header("Content-disposition: form-data; filename=\"$outputfilename\""); $fp=fopen($filename,'r'); while (!FEof($fp)): $filedata.=fread($fp,8192); endwhile; fclose($fp); echo $filedata; ?> The problem is, that the file on server has 16857 bytes and saved file has 16858. In another case downloaded file has everytime 1 byte more than the original file on server. When I put JPEG or ZIP forexample to output, there is no problem with opening file like this. Bud when I am trying .docx (Office2007 file format) it occures mistake during opening this file in MSOffice... Can anybody s me with this problem? Why is the file size increasing one byte? Whitch byte it is? Thanks a lot! Pavel |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Pavel Janda wrote:
> Hello to everybody, > > I have this problem with downloading files via PHP. For illustration - I > am using this fragment of code: > > <?php > > header("Content-type: $contenttype; name=\"$outputfilename\""); > header("Content-disposition: form-data; filename=\"$outputfilename\""); > > $fp=fopen($filename,'r'); > while (!FEof($fp)): > $filedata.=fread($fp,8192); > endwhile; > fclose($fp); > echo $filedata; > > ?> > > The problem is, that the file on server has 16857 bytes and saved file > has 16858. In another case downloaded file has everytime 1 byte more > than the original file on server. > > When I put JPEG or ZIP forexample to output, there is no problem with > opening file like this. Bud when I am trying .docx (Office2007 file > format) it occures mistake during opening this file in MSOffice... > > Can anybody s me with this problem? Why is the file size increasing > one byte? Whitch byte it is? > > Thanks a lot! > Pavel Probably that whitespace after your last ?> What I would recommend is to just leave off the last ?>, it's not required and by not adding it you won't see those annoying problems with whitespaces causing corrupt data. - Tul |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
Thanks a lot. However there wasn't any visible whitespace in code,
leaving of ?> ed... I haven't known, that it is not required ).Thank you very much again! Pavel M. Sokolewicz napsal(a): > Pavel Janda wrote: >> Hello to everybody, >> >> I have this problem with downloading files via PHP. For illustration - >> I am using this fragment of code: >> >> <?php >> >> header("Content-type: $contenttype; name=\"$outputfilename\""); >> header("Content-disposition: form-data; >> filename=\"$outputfilename\""); >> >> $fp=fopen($filename,'r'); >> while (!FEof($fp)): >> $filedata.=fread($fp,8192); >> endwhile; >> fclose($fp); >> echo $filedata; >> >> ?> >> >> The problem is, that the file on server has 16857 bytes and saved file >> has 16858. In another case downloaded file has everytime 1 byte more >> than the original file on server. >> >> When I put JPEG or ZIP forexample to output, there is no problem with >> opening file like this. Bud when I am trying .docx (Office2007 file >> format) it occures mistake during opening this file in MSOffice... >> >> Can anybody s me with this problem? Why is the file size >> increasing one byte? Whitch byte it is? >> >> Thanks a lot! >> Pavel > > Probably that whitespace after your last ?> > What I would recommend is to just leave off the last ?>, it's not > required and by not adding it you won't see those annoying problems with > whitespaces causing corrupt data. > > - Tul |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
M. Sokolewicz wrote:
> Pavel Janda wrote: >> Hello to everybody, >> >> I have this problem with downloading files via PHP. For illustration - >> I am using this fragment of code: >> >> <?php >> >> header("Content-type: $contenttype; name=\"$outputfilename\""); >> header("Content-disposition: form-data; >> filename=\"$outputfilename\""); >> >> $fp=fopen($filename,'r'); >> while (!FEof($fp)): >> $filedata.=fread($fp,8192); >> endwhile; >> fclose($fp); >> echo $filedata; >> >> ?> >> >> The problem is, that the file on server has 16857 bytes and saved file >> has 16858. In another case downloaded file has everytime 1 byte more >> than the original file on server. >> >> When I put JPEG or ZIP forexample to output, there is no problem with >> opening file like this. Bud when I am trying .docx (Office2007 file >> format) it occures mistake during opening this file in MSOffice... >> >> Can anybody s me with this problem? Why is the file size >> increasing one byte? Whitch byte it is? >> >> Thanks a lot! >> Pavel > > Probably that whitespace after your last ?> > What I would recommend is to just leave off the last ?>, it's not > required and by not adding it you won't see those annoying problems with > whitespaces causing corrupt data. I agree. Also a much simpler way of outputting a file that doesn't use up memory, is just to replace: $fp=fopen($filename,'r'); while (!FEof($fp)): $filedata.=fread($fp,8192); endwhile; fclose($fp); echo $filedata; With: readfile($filename); http://uk.php.net/manual/en/function.readfile.php Col. |
|
![]() |
| Outils de la discussion | |
|
|