473,657 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_conten ts(UPLOAD_PATH. $storedName);
if($mimeExtensi on == '')
{
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 2829
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_conten ts(UPLOAD_PATH. $storedName);
if($mimeExtensi on == '')
{
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
2398
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" events described and coded for in the examples mdb file.. However - some other important events I cannot get to work - some are: DocumentBeforeClose DocumentBeforePrint DocumentBeforeSave
8
9162
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 C can be used to perform this task. Thanks you so much
0
1467
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 methods I can think to try. We are using COM objects, because we need compatibility with Word 2000. I am testing this against Word 2003 however. For simplicity sake, I have two documents open, 1.doc and 2.doc.
3
6117
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 done this? Does it seem possible? I followed the instructions from a sample on the Microsoft knowledge base but it only seems to work when creating a VB.NET Windows .EXE, not an VB.NET ASP app.
12
1937
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 = "application/x-msdownload" Response.AddHeader("Content-Disposition", "attachment; filename=" & System.IO.Path.GetFileName(FilePath)) Response.AddHeader("Content-Length", File.Length.ToString()) Response.WriteFile(FilePath) Response.End()
16
1722
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) objWord.Documents.Item(letterfile).Activate() Catch MsgBox("Error - Word Not running properly - letterfile=" & letterfile &
4
2048
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 cancelled message appears in a browser window. If you cut and paste this same link into IE and attempt to saves there is no browser window opened. If the user attempts to open instead of save the document it opens in a word out side the browser. I am...
1
1420
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 word document), i found that the content is not correct.. lets say the original content is "This is a word document"..after downloading the file..the content becomes "&@%&*@**)@!)(!@)((___@!#" (some invalid unreadable characters).. what cause...
2
20157
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 switch back to "Left" aligned for remaining paragraphs, the text within the Word document remained Centered. I'm using: VS2008 w/ .NET Framework 3.5, Microsoft.Office.Interop.Word Version 12.0.0.0, and I'm creating the document as a 97-2003 document...
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8740
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.