opening word document in browser using php

Discussion in 'PHP' started by learnerabn, Aug 7, 2010.

  1. #1
    hi all,

    I am having an hyperlink in my site,if i click in that i want to open an word document.That word document should be opened in browser itself.
    can any one help me to do this....

    Thanks in advance.
     
    learnerabn, Aug 7, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    I haven't tried it and its going to depend on what type of word document you have, but what you do is add this line to a .htccess file, where I have EDIT that's where you put the doc type example doc, docx or wps

    
    AddType application/x-httpd-php EDIT
    
    PHP:
    Just to let you know, I haven't tested this, but I cant see it working at all, it would be better to convert your docs to html or pdf before you upload them, however this is how you open it in a browser rather then your browser trying to download it, which is what you asked ?
     
    MyVodaFone, Aug 7, 2010 IP
  3. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for your reply MyVodaFone,
    can i know for what it helps.
    bcoz i want to open the word document in browser itself.
     
    learnerabn, Aug 7, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Basically you cant do what you want, you must convert your docs first.

    The word 2007 program will allow you to save your docs in many different formats, I suggest you just save them as a "web page" or "PDF"

    The only other option you have which makes things more complicated is to use any of the free scripts found around the net, try searching phpclasses.org or hotscripts.com for doc - html or pdf
     
    MyVodaFone, Aug 7, 2010 IP
  5. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you MyVodaFone,

    I tried it but no solution.
    I Gmail or other mail account if we click on the view link in the attachment means that
    page will open in the new tab but in the attachment format na...
    Thats what i want
    how can i do like that?
     
    learnerabn, Aug 7, 2010 IP
  6. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #6
    You can use Google Docs Viewer for that. Even if you open it in the browser itself (it is possible), the user will see nothing but garbage characters because you'll have to convert the file beforehand. Some users who uses Chrome as their browser has an extension that automatically open any .doc files from the browser with Google Docs Viewer.
     
    Rainulf, Aug 7, 2010 IP
  7. learnerabn

    learnerabn Peon

    Messages:
    131
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks a lot to you Rainulf,

    I tired it and got it.
    But i have a doubt, i want to display dynamic word document according to the user input.
    can i do this with Google Docs Viewer?

    Thanks in advance.
     
    learnerabn, Aug 9, 2010 IP
  8. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #8
    I'm not sure what you mean, I'm assuming you want to view document file of user input.

    In order to do that, you'll need to let users upload their document files to your website and then finally sending the link from that doc file to Google Docs Viewer.
     
    Rainulf, Aug 9, 2010 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    <?php
    //example...
    $doc = 'http://www.phpguru.org/downloads/PCRE Cheat Sheet/PHP PCRE Cheat Sheet.pdf';
    
    //get google viewer url...
    echo 'http://docs.google.com/viewer?url='.urlencode($doc);
    
    //or get html of doc...
    echo file_get_contents('http://webcache.googleusercontent.com/search?q=cache:tpOT17RuGWAJ:'.urlencode($doc);
    ?>
    PHP:
     
    danx10, Aug 9, 2010 IP