-5

My Question is I am uploading a file(.pdf/.doc) and saving it in a folder and storing the path of the file in mysql using php.

In the Next form i want to display the contents of uploaded file using php.

  • 4
    Here's a link for doc files http://stackoverflow.com/questions/5334301/how-do-you-display-a-formatted-word-doc-in-html-php and here's one for pdf http://stackoverflow.com/questions/18393665/embed-the-pdf-in-a-webpage-without-using-the-built-in-pdf-viewer All you have to do is put the right file from sql – Dipen Shah Jun 30 '15 at 12:49
  • Can i know why i got -ve points to my question kindly please remove the -ve one and suggest me better way to ask questions. Thank you – chandrasekhar Jun 30 '15 at 12:52
  • I am not the one who downvoted you but as a suggestion I can advice you this: Put sample code, what have you tried so far and your expected output. Please take time to read this http://stackoverflow.com/help/how-to-ask – Dipen Shah Jun 30 '15 at 12:54
  • 2
    Your question shows no research effort. – Fjodr Jun 30 '15 at 12:55

1 Answers1

1

Yes you can do that

specifically if you want to display pdf in browser you need something like this.

<?php
 $file = 'path/to/PDF/file.pdf';
 $filename = 'filename.pdf';
 header('Content-type: application/pdf');
 header('Content-Disposition: inline; filename="' . $filename . '"');
 header('Content-Transfer-Encoding: binary');
 header('Accept-Ranges: bytes');
@readfile($file);
?>  

for word file its a little work you need to do

   function readDocs($filename){

            $striped_content = '';
            $content = '';

            if(!$filename || !file_exists($filename)) return false;

            $zip = zip_open($filename);

            if (!$zip || is_numeric($zip)) return false;

            while ($zip_entry = zip_read($zip)) {

                if (zip_entry_open($zip, $zip_entry) == FALSE) continue;

                if (zip_entry_name($zip_entry) != "word/document.xml") continue;

                $content .= zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));

                zip_entry_close($zip_entry);
            }// end while

            zip_close($zip);


            $content = str_replace('</w:r></w:p></w:tc><w:tc>', " ", $content);
            $content = str_replace('</w:r></w:p>', "\r\n", $content);
            $striped_content = strip_tags($content);

            return $striped_content;
        }

        // using function to finally get contents
        $content = readDocs("path/to/the/file");
        if($content !== false) {

            echo nl2br($content);
        }
        else {
            echo "File Not Found";
        }
Meenesh Jain
  • 2,532
  • 2
  • 19
  • 29