473,386 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Downloaded word document not correct

Hi everyone,

I'm using PHP and a DB to control access to files that have been
uploaded by users. I am using the following PHP code snippet to
deliver the file after the access rights have been checked.

$theFile = file_get_contents(UPLOAD_PATH.$storedName);
if($mimeExtension == '')
{
header("Content-Type: application/octet-stream\n");
}
else
{
header("Content-Type: $mimeExtension\n");
}
header("Content-Disposition: attachment; filename=
\"$documentName\"\n");
// doesn't work with base64 or binary
header("Content-Transfer-Encoding: binary\n");
header("Content-length: " . strlen($theFile) . "\n");

echo $theFile;

Now, text files open up fine. Word documents though, especially those
with embedded photos, come out mangled. I have tried sending the word
document with the content type being sent to both application/octet-
stream and the word document one. The file on the server (which is my
computer, as I am currently developing the site) is fine. This means
that something goes wrong while the file is being sent. I suspect the
Content-Transfer-Encoding header, but setting it to binary (which was
my original code) or base64 doesn't fix the problem. What could
possible be the problem?

Secondly, when the user presses 'save', the save button remains
depressed until the document has finished uploading. It's as if the
save operation 'blocks', rather than adding the save to the download
manager and getting rid of the save screen. That is, the 'save as'
screen remains visible, with the save button pressed down, until the
file is completely downloaded. How can I avoid this?

Cheers

Taras

Mar 10 '07 #1
1 2815
In case anyone runs into the same problem, the problem I was having
was caused because output buffering was turned on. Turning off output
buffering solved the problem.

Couple of questions though:

1) Why would only word documents get confused by this? I could
succesfully download PDFs with ob buffering turned on, for example.
2) I checked the buffer to see what was in it just before turning it
off. It had "\r\n\r\n" which, in HTTP, indicates that header data has
finished and what follows is actual data. Where did these characters
in the buffer come from?
3) Related to question 2. Even though the buffer had data in it prior
to sending headers, I could succesfully send headers. Usually if you
try to send headers after outputting data PHP throws an error.

On Mar 10, 4:21 pm, "Taras_96" <taras...@gmail.comwrote:
Hi everyone,

I'm using PHP and a DB to control access to files that have been
uploaded by users. I am using the following PHP code snippet to
deliver the file after the access rights have been checked.

$theFile = file_get_contents(UPLOAD_PATH.$storedName);
if($mimeExtension == '')
{
header("Content-Type: application/octet-stream\n");
}
else
{
header("Content-Type: $mimeExtension\n");
}
header("Content-Disposition: attachment; filename=
\"$documentName\"\n");
// doesn't work with base64 or binary
header("Content-Transfer-Encoding: binary\n");
header("Content-length: " . strlen($theFile) . "\n");

echo $theFile;

Now, text files open up fine. Word documents though, especially those
with embedded photos, come out mangled. I have tried sending the word
document with the content type being sent to both application/octet-
stream and the word document one. The file on the server (which is my
computer, as I am currently developing the site) is fine. This means
that something goes wrong while the file is being sent. I suspect the
Content-Transfer-Encoding header, but setting it to binary (which was
my original code) or base64 doesn't fix the problem. What could
possible be the problem?

Secondly, when the user presses 'save', the save button remains
depressed until the document has finished uploading. It's as if the
save operation 'blocks', rather than adding the save to the download
manager and getting rid of the save screen. That is, the 'save as'
screen remains visible, with the save button pressed down, until the
file is completely downloaded. How can I avoid this?

Cheers

Taras

Mar 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: astro | last post by:
I've been looking at the event sinking example in Litwin et. al. "Access 97 Developer's Handbook" and I am able to event sink the 2 events listed - those being the "_quit" and "_documentchange"...
8
by: Asma | last post by:
Dear Sir, I am trying to find a way to open a Word document using C language and read the text of word doc into a variable. (Turbo C on Dos 6.0). Can anyone please tell me which libraries in...
0
by: Steve | last post by:
I am noticing a problem when interfacing with Word through my C# code. What I am trying to do is enumerate through the documents currently open in Word. I have noticed issues with this on both...
3
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone...
12
by: Rob Nicholson | last post by:
We've implemented functionality to allow a user to download a document (any document type) from the IIS server using the following code: Response.Clear() Response.ContentType =...
16
by: Simon Verona | last post by:
I have a problem with automating MS Word through vb.net My code is : Dim objword As new Word.ApplicationClass Try objWord.Documents.Open(letterfile)...
4
by: =?Utf-8?B?S29sbG1vcmdlbg==?= | last post by:
I have an asp page that outputs a word document. Wnen the user attempts to open this page from a hyberlink in an email document the word document opens fine but if they save then an action...
1
by: h3ctor83 | last post by:
hello everyone.. can anybody help me? i made an application to upload files to the server.. and after that use ris able to download that file again.. but after downloading the file (specifically...
2
by: uamusa | last post by:
I am Dynamically generating a proposal(report) in MS Word. By default the Paragraph Alignment is "Left". For the First 6 Paragraphs I set the Alignment to "Center", and then when attempting to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.