Page 1 of 4 123 ... LastLast
Results 1 to 10 of 34
  1. #1

    Default Retrieving and Displaying Doc/txt files in php??..help.


    hi guys,
    im working on a project in fulfillment of my ojt, one of the task is to be able to upload doc/txt files in the database and then you can view all the uploaded doc/txt files. I am finished with the uploading part, i uploaded the file in a folder in the server while saving the path in the database but what concerns me most is how do can retrieve the file and display it using php??..

    plssss if anyone can help me..badly need your help..

  2. #2
    I won't give you the full answer, since this is a homework question, but I'll give you some clues.

    - Set your Content-Type header to "application/msword".
    - use readfile() or other PHP functions to print out the file

  3. #3
    Quote Originally Posted by ichiriki View Post
    hi guys,
    how do can retrieve the file and display it using php??..

    plssss if anyone can help me..badly need your help..
    All you have to do is locate the path of the files you intend to read then use the function given by the simoncpu or the likes. I think it would be better if you try coding it and show it to us here then we can help you debug if it will have some problems.

    good job,

  4. #4
    uhmmm...i have a similar php file in which i am to display an image file..it works..i just used fpassthru(); function to gather all the data in the file..is this still applicable in retrieving a doc file content??
    heres my code in displaying a photo i uploaded:
    <?php
    $image_folder = 'file:///C:/upload/photo/';
    if (isset($_GET['name']) && basename($_GET['name']) == $_GET['name']) {
    $pic = $image_folder.$_GET['name'];
    if (file_exists($pic) && is_readable($pic)) {
    $ext = substr($pic, -3);

    switch ($ext) {
    case 'jpg': $mime = 'image/jpeg'; break;
    case 'gif': $mime = 'image/gif'; break;
    case 'png': $mime = 'image/png'; break;
    default: $mime = false;
    }
    if ($mime) {
    header('Content-type: '.$mime);
    header('Content-length: '.filesize($pic));
    $file = @ fopen($pic, 'rb');

    if ($file) {
    fpassthru($file);
    exit;
    }

    }

    }
    else
    {echo "Sorry File is No Longer Readable";}

    }
    ?>
    ive just DL this code and edited it...

  5. #5
    ive tried this code:
    <? include('db.php'); ?>
    <?
    $doc_folder = 'file:///C:/upload/documents/cdn.doc';

    $filename = $doc_folder;
    header('Content-disposition: attachment; filename='.basename($filename));
    header("Content-Type: application/msword");
    header('Content-Length: '. filesize($filename));
    readfile($filename);
    ?>
    it opens the file in the ms word but not in the browser...i would like to print it in the browser f possible..help plss..

  6. #6
    Quote Originally Posted by simoncpu View Post
    I won't give you the full answer, since this is a homework question, but I'll give you some clues.

    - Set your Content-Type header to "application/msword".
    - use readfile() or other PHP functions to print out the file
    master ngano i change man ang content-type header?

  7. #7
    I think the headers are case sensitive. Try using Content-Disposition instead of Content-disposition.

    It's kindda weird though. According to the RFC, field names are supposed to be case-insensitive...

    EDIT:
    Try "Content-Type: application/octet-stream" diay. Lahi diay ang behavior sa imong browser kung application/msword. Sorry...
    Last edited by simoncpu; 09-03-2008 at 04:09 PM.

  8. #8
    Quote Originally Posted by Tin_Tin View Post
    master ngano i change man ang content-type header?
    Mistress Tin_Tin,

    Some web servers don't automatically detect the file type, so what happens is that random characters are instead sent to the browser.

    Please see FAQ for more info...

    [ simon.cpu ]

  9. #9
    Quote Originally Posted by simoncpu View Post
    Mistress Tin_Tin,

    Some web servers don't automatically detect the file type, so what happens is that random characters are instead sent to the browser.

    Please see FAQ for more info...

    [ simon.cpu ]
    bro ko master uy. . . kasabot nko, tried coding it mu display siya ug mga garbage nga characters. . .

  10. #10
    Quote Originally Posted by Tin_Tin View Post
    bro ko master uy. . .
    Yikes... abi nako chix...

  11.    Advertisement

Page 1 of 4 123 ... LastLast

Similar Threads

 
  1. Display and store image in php/mysql.. HELP!
    By cutterpillow20 in forum Programming
    Replies: 18
    Last Post: 03-12-2013, 08:52 AM
  2. Error in PHP! Help..
    By cutterpillow20 in forum Programming
    Replies: 9
    Last Post: 10-06-2012, 06:10 PM
  3. Replies: 12
    Last Post: 10-30-2008, 01:24 PM
  4. Streaming/Playing videos in PHP..help.
    By ichiriki in forum Programming
    Replies: 3
    Last Post: 10-08-2008, 05:15 PM
  5. Search image and display in VB?
    By franzziss in forum Programming
    Replies: 9
    Last Post: 10-15-2007, 10:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top