View: 2141|Reply: 3
|
Bagaimana nak open file word dalam php?
[Copy link]
|
|
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 #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 #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 #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 ] |
|
|
|
|
|
|
| |
|