473,327 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

View PDF & Doc Files Without Downloading them

Hello guys,

I have been able to work on this code in this article uploading files into MySQL database using php and it is working well.

But now I want to be able to allow users just view the PDF or doc files without having to download them.

Please I need help on this.

Thanks
May 30 '13 #1
10 21114
Frinavale
9,735 Expert Mod 8TB
Hi Abramfas,

This is going to depend on the browser.

If the browser knows how to open the file, then it will do so. If the browser does not know what to do it will give the user the option to download the file so that they can open the file in an application that does know how to open it.

For example, if the browser has a plug-in installed that allows users to view PDF files, it will use the plugin to display the file. If the browser does not have a plugin installed, it will popup a dialog that lets the user save the file to their computer so they can open it with an application that knows how to view PDF files.

If you want to display the file on the same page as your content, consider using an <iframe> who points to the PDF file that you wish to let the user view. This way the browser will display the file using the appropriate plugin if it can, or else the user will be prompted to download the file.

You could also open a new window if you are not comfortable using <iframe>s.


-Frinny
May 30 '13 #2
Oralloy
985 Expert 512MB
Abramfas,

Are you trying to emulate what google mail does with attached documents, rendering them as HTML? Or, are you simply trying to display the full-document using a plug-in, as Frinny described?

--Oralloy
May 30 '13 #3
Orally,

I am trying to display the full document with a plugin.

Frinavale,

How do I insert an iframe am a bit new in php programing
May 30 '13 #4
Oralloy
985 Expert 512MB
Abramfs,

Sounds like you are on the right path, then. I'll step out.

From reading your request, I didn't know what your goal was. I've had folks want to do limited display of documents, as pre-sales teasers, so I thought I'd ask.

As for iframes, they are a type of HTML tag, this page at W3Schools can give you a bit of information.

Luck!
Oralloy
May 30 '13 #5
Frinavale
9,735 Expert Mod 8TB
The link that @Oralloy posted is a good starting point for learning about iframes.

You would insert an iframe the same way as you would insert any HTML using php.

-Frinny
May 30 '13 #6
Luuk
1,047 Expert 1GB
But "View PDF & Doc Files Without Downloading them"
will never be possible,

Because you need to download something to be able to view anything.......

;)
May 31 '13 #7
Thannks guys,

But am still not able to resolve the issues. I am trying to view the PDF inline let me show you the edited vasion am working with.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  $server = 'localhost';
  3.  $user = 'root';
  4.  $pass = '';
  5.  $db = 'database';
  6.  
  7.  // Connect to Database
  8.  $connection = mysql_connect($server, $user, $pass) or die ("Could not connect to server ... \n" . mysql_error ());
  9.  mysql_select_db($db) or die ("Could not connect to database ... \n" . mysql_error ());
  10.         $id = intval($_GET['id']);
  11.         $file=  'SELECT `name`, `mime`,`size`, `created` FROM `tablename`';
  12.         $result = mysql_query($file);
  13.  
  14. if($d = mysql_fetch_array($result))
  15. {
  16.     $file = $d['name'];
  17.     header('Content-type: application/pdf');
  18.     header("Content-Disposition: inline; name=".$row['name']);
  19.     header('Content-Transfer-Encoding: binary');
  20.     header('Content-Length: ' . size($file));
  21.     header('Accept-Ranges: bytes');
  22.     header("Location: $file");
  23.     @readfile($file);
  24. }
  25. else{
  26.     echo'No file with the specified ID exists';
  27. }
  28. ?>
  29.  
Jun 10 '13 #8
Luuk
1,047 Expert 1GB
Line 10: What is the use of $id ?
Line 18: Where did $id['name'] get a value ?
Line 20: 'size()' is an unknown function
Jun 11 '13 #9
is there any optionto preview and print files instead of downloading
Aug 25 '16 #10
Luuk
1,047 Expert 1GB
@shruthi gs: if you have any question, please create a NEW question.
Do NOT pollute an old thread with a new question...
Aug 25 '16 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave | last post by:
Dear Sirs, Is there a way to get the width and height of an image without downloading the image, or with just downloading a minimal portion of the image? For instance, I have a list of 10,000...
3
by: ACaunter | last post by:
Hi all, I was wondering if there was a way a client's machine could play audio or view a word document which is stored on the server, without having them download it first. This will be done over...
15
by: Sandra-24 | last post by:
I was reading over some python code recently, and I saw something like this: contents = open(file).read() And of course you can also do: open(file, "w").write(obj) Why do they no close...
4
by: aldonnelley | last post by:
Hi there: a bit of a left-field question, I think. I'm writing a program that analyses image files downloaded with a basic crawler, and it's slow, mainly because I only want to analyse files...
2
by: ankita | last post by:
Hello, i am using Asp.net application to read contents of FTP folder. I just want to have names of all folders/files that are inside FTP directory. So for that i don't want to download any...
1
by: shreya | last post by:
Hi , How can i view *.class files. I don't have .java files i have only *.class files.how could i view the code Could someone help
1
by: psabro | last post by:
how can i create a java chat room so that every one can join it without downloading any thing like java, java applets or some thing else?
11
by: karthi84 | last post by:
hi, if i have selected view hidden files and folders option from the folder option it is not enabled. at the time of applying it works but if i close that window and open it again its not...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.