473,714 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get file contents

160 New Member
hi to all

i am trying to get contents of a file in php.my code is
Expand|Select|Wrap|Line Numbers
  1. $filename = $filepath;
  2. $handle = fopen($filename, "r");
  3. $contents = fread($handle, filesize($filename));
  4. fclose($handle);
  5. echo $contents;
but i am getting a problem that file contents is showing in the form of encode

Wؓђ?ђ? @ؓ@?? ਚٲ䉁咀蓀,m0? ????ђ $ؓؓؓؓؓؓؓBB ؓؓؓ?ؓؓؓؓ????? ?????????????ؓ ؓؓؓؓؓؓؓؓ? ?: aaaaaaaaaaaaaa aaaaaaaaaaaaaaa a ?h2 ؀h? Ӏ?,1?h? Я ?ཡ??"??#??$? ?%??Ђ?Ђ ?Ђf ???????? ?6666666 66vvvvvv vvv6666 66>66666 6666666 66666666 6666666 ?6666666 666?

can you please help me in getting correct content of file
Jun 4 '09 #1
15 4697
8,658 Recognized Expert Moderator Expert
what is the content supposed to be? what is character encoding in the file?
Jun 4 '09 #2
160 New Member
that is simple word file means .doc file.and in file there is only content is "aaaaaaaaaaaaaa aaaaaaaaa"
Jun 4 '09 #3
8,658 Recognized Expert Moderator Expert
there's no chance properly reading a .doc with fread() (because of the included proprietary formatting). you may use the COM extension to read a Word file.
Jun 4 '09 #4
160 New Member
hmm.okz.thanks. can you please refer me tutorial of reading content of a .doc file in php.
Jun 4 '09 #5
8,658 Recognized Expert Moderator Expert
since I can't use COM I can't advice one. some hints you'll get when reading through the manual, otherwise consult google.
Jun 4 '09 #6
160 New Member
okz.Dormilich thanks again
Jun 4 '09 #7
5,058 Recognized Expert Expert

Just to point out...

If you just want to read a .doc file through PHP, like your code appears to be doing, you can do that without needing to actually use the file.
You would just leave it up to the client's browser to deal with how to use it.

For example;
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $filename = "/path/to/some/file.doc";
  4. // Let the browser know it's getting a word document
  5. header("Content-Type; application/msword");
  7. // Send the file
  8. readfile($filename);
  9. ?>
That would just feed the file through to the browser, which would most likely pop up a download dialog, or open it in a Word window.

If you actually wanted to use the word document in your PHP code, that's a much much harder task.

Microsoft don't really play well with others, and seeing as PHP is a open-source project...
Jun 4 '09 #8
160 New Member
Thanks Atli

yes Atli i just want to show content of .doc file.editting is not required

Atli using this code also me get same problem.means output on browser is shown like this

 0@P`p€  0@P`p€  0@P`p€  0
Jun 4 '09 #9
5,058 Recognized Expert Expert

Try adding the Content-Disposition and Content-Length headers.
That should tell the browser to download or open the file.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $filename = "/path/to/some/file.doc";
  4. // Let the browser know it's getting a word document
  5. header("Content-Type; application/msword");
  6. header("Content-Disposition: attachment; filename=". basename($filename)); 
  7. header("Content-Length: ". filesize($filename));
  9. // Send the file
  10. readfile($filename);
  11. ?>
Jun 4 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: chuck amadi | last post by:
By the way list is there a better way than using the readlines() to > > >parse the mail data into a file , because Im using > > >email.message_from_file it returns > > >all the data i.e reads one entire line from the file , headers as well > > >as just the desired body messages . > > > > > >fp = file("/home/chuck/pythonScript/testbox") > > >mb = mailbox.UnixMailbox(fp, > > >email.message_from_file)
by: Foxy Kav | last post by:
Hi, another question from me again, i was just wondering if anyone could give me a quick example of reading data from a file then placing the data into an array for some manipulation then reading that array back into another file. I've tried, but i can only read the data and place it on the screen, i cant get it into an array. Any help would be helpful.
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. How do i make the last pointer in the indirect sector that has another level of indirect pointer, and be defined recursively to support infinite large files? -code-
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had problems getting my algorithm to work and in order to help me find the solution I decided to print each line to screen as I read them. Then, to my surprise, I noticed that there was a space between every character as I outputted the lines to the...
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
by: Patrick | last post by:
Hi All, I have numerous files that look like the chunk below. From the date and time I calculate a year day value. For the example that value is 148.67721064815 I'm not an expert yet at dealing with arrays, but I get around well in php otherwise (reading data files, loops, functions, etc). My question is how would I go about creating an array that would hold
by: Gan Quan | last post by:
I'm writing a c++ program that has many (100+) threads read/write files simultaneously. It works well if not considering the efficiency. The file i/o seems to be the bottleneck. This is my code to read from and write to files: #include <fstream> #include <sstream> #include <string>
by: snitu | last post by:
hello i am new user of this forum. i have a problem in javascript code. plz. give me idea about how to create tree using xml file (not using xsl file) in javascript. i am also sending my xml file . <?xml version="1.0"?> <tree> <entity id="e1"> <description>Customers</description> <oncontextmenu></oncontextmenu>
by: programming | last post by:
hi all, here is the php code! i am trying to use to 'edit' hyperlink to edit txt in member.txt. Problem is that it reads the values ok into an array, however when i attempt and update new values into the file, i get no results. Does anybody know where i am going wrong???? <? session_start(); // Set updated content for user
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.