CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 2140|Reply: 3

Bagaimana nak open file word dalam php?

[Copy link]
Post time 20-8-2007 01:42 AM | Show all posts |Read mode
hai..apa kabar suma!!
okay, nak tanya,code php di bwh tujuannya nak open fail dalam txt.it is works.tapi, bila
nak open fail dalam word, dapat bukak, tapi isi kandungan dalam fail dah jadi cacing2,i mean
tak sama ngan content sebenar..
so sy nak minta consult kat suma yg pandai2 ni, apa kesalahan kod php kat bwh ni.
macamana caranya nak open fail dalam word,i mean cara yg betul yang mengeluarkan output yang
sepatutnya...ok!

<?php
$filename = "sam.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
//paaprkan kandungan
echo ("$contents");
?>
Reply

Use magic Report


ADVERTISEMENT


Post time 20-8-2007 02:56 AM | Show all posts

Reply #1 HishamZ's post

If i'm not mistaken, the file code .txt refers to the file yang telah dicreatekan dan disavekan dalam NOTEPAD or WORDPAD. For files yang dicreatekan dan disavekan under Microsoft WORDS, the file should be with .doc

file name: LOGO
Saved under notepad or wordpad: LOGO.txt
Saved under microsoft words: LOGO.doc

KALAU tak silap la yer. Kalau silap, maaf dipinta.
Reply

Use magic Report

 Author| Post time 20-8-2007 02:12 PM | Show all posts

Reply #2 lealaurielle's post

yes..kalo .txt for sure la notepad..and .doc for word.
for your information, sy dah try .doc before, tapi tak jadi, kuar simbol2.tak kuar pun text
yang ingin sy paste kan tu.

please read carefully at my first post.
Reply

Use magic Report

Post time 20-8-2007 11:38 PM | Show all posts

Reply #3 HishamZ's post

itu aku bg salah satu cara.. iaitu tukar jd txt dulu then baru display...
$word = new COM("word.application") or die("Unable to instantiate Word");
$word->Documents->Open($filename);
$new_filename = substr($filename,0,-4) . ".txt";
echo
// the '2' parameter specifies saving in txt format
$word->Documents[1]->SaveAs($new_filename,2);
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = NULL;
unset($word);

$fh = fopen($new_filename, 'r');
// this is where we exit Hell
$contents = fread($fh, filesize($new_filename));
fclose($fh);
unlink($new_filename);


tp aku ada try gak surf intenet.. sumer xde la nk display content tuh.. tp cara terbaik semasa nk suh baca file word tuh, kita dunload file tersebut

cth

header ("Content-type: application/x-msword");
header ("Content-Disposition: attachment; filename=\"" . basename($filename) . "\"" );
header ("Content-Description: PHP/INTERBASE Generated Data" );
readfile($filename);

so pandai2 la ko mgubah coding nih mgikut kesuaian coding ko.. aku bg clue jer..

[ Last edited by  liverpoolfctv at 20-8-2007 11:39 PM ]
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

3-1-2025 03:09 AM GMT+8 , Processed in 0.051131 second(s), 17 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list