How to display(not download) files on a webpage in php? - php

I am showing a list of files on a webpage. Files may be of any type like pdf,doc,excel,txt etc.
What i want is when some one click on an item of the list then that file should be displayed in another tab. I dont want to download the file. I just want them to be visible so that user can read it.
I try this using php for pdf files i am able to get the plain content of the file but i want a viewer type of thing.
Can i achieve this?
If yes can i achieve this in php?
If yes then how?
Thanks and Regards
Sumit Rathore

downloading or viewing any file in browser depends on browser setting.
for example in firefox in Options - > Applications Tab you can change state of reading a file that can be downloading or viewing.
now, for display a file to visitor best solution is creating a special php or flash app.
Good Luck.
see http://view.samurajdata.se/

<html>
<body>
<embed src="www.dedoimedo.com-apache-web-server-lm.pdf">
</body>
</html>
This code is working in google chrome but not in other browsers.

Related

How to save webpage with all styles and images similar to evernote?

If you look at evernote or use their web clipper browser addon, it can save a webpage completely with all styles and images of page clipped. So for example if I save this very page with it, it will be saved as is.
Does any one have an idea of how evernote does it? I want to do it with either PHP or JavaScript but am not sure how to save a webpage with all styles and images. I know about Internet Explorer's mht format but that's not what evernote does.
So basically it would be great if one can save a webpage with all styles and images (excluding dynamic content such as JS) in single file and be able to open it in any major browser ? Any pointer to such script would also be helpful.
I have also noticed similar thing in Gmail, when you copy any part of page and paste that in Gmail Compose, it renders it as it was or same happens in MS Word too.
Thanks for your help and hints :)
Replace linked stylesheets with style blocks containing the CSS copied from the linked stylesheets. Replace image sources with data URLs.
Or just shell out a call to wget -mk and mirror the site:
<?php
system('wget -mk http://foo.com/bar');
?>
You could do file_get_contents() and then go and recursively download whatever scripts/images you need.

Allow user to save a html/php/css page as a pdf?

I have a "calculator" page that calculates a load of maths based on what the user inputs. The user can then click "get results" to show their full calculations.
I then have a button - "save as pdf" which I want it to allow the user to save a pdf of their results.
It's a combination of html, php, css combined with Wordpress.
How can I (on click) convert the results to a pdf and allow the user to save?
p.s I know this been asked a few times but I can't seem to find the correct answer or a working version... or a tool with good documentation for me to follow!
Check also FPDF
Generally these things are solved on the server. Clicking the link would trigger a redirect to the php page and in general instead of writing output to a webpage, you write output to a pdf stream (still arrives in the browser but the browser knows it as a pdf).
you do this by changing the response headers. you could use this library to write out the pdf file
http://code.google.com/p/wkhtmltopdf/ make sis pretty simple, you could do a curl request to the page, and send it to the library.

how to make an interactive uploader like gmail and facebook have?

I want to make a interactive uploading option like Facebook and gmail have where they show the progress of the current file in uploading and then show the respective image or name of the file over there after the upload.
Right now, i'm using php and normal html for uploading where i send the file from one page to another where php handles it accordingly but i want a interactive one which show the progress also on the same page and then the name of the file after uploading without page refresh.
I knew, it can be done with ajax and css but i don't know how. All i want a interactive upload-er which uploads the file and then provide me the respective file name.
Gmail uses firefox file api, read more about it here https://developer.mozilla.org/en/Using_files_from_web_applications
Or check this live demo
http://robertnyman.com/html5/fileapi-upload/fileapi-upload.html
Hope this will help/solve ur problem ;) best luck

Create labels on pdf

i want to open PDF file in a iframe OR windows Extjs
and let user click to add labels
what scripts can i use ?
im coding with Extjs / php /mysql
i use fpdf/fpdfi libraries to write on a PDF file
any idea ? help please
thank
Simply pointing iframe to PDF file only works when user has allowed it's web browser to embed Adobe Reader (I'm not even sure that other PDF-readers support this at all). This might be the common configuration for IE users, but in other browsers and especially on other OS-es it's not as common.
Another option is to use a service that renders your PDF as web page. For example using google docs it's dead easy:
<iframe
src="http://docs.google.com/gview?url=http://yourdomain.com/file.pdf&embedded=true"
style="width:600px; height:500px;"></iframe>

Image Preview using AJAX in PHP

How should i create a preview of image to be uploaded before it is actually submitted using AJAX in PHP?
Without uploading the image, this is going to be impossible in JavaScript as far as I can see, because security limitations are going to prevent you from determining the selected file in the file upload, and embedding that file in an img tag (as it used to be possible five years ago.)
You will be more lucky with Flash-based uploaders. I have seen some that offer the kind of functionality you want.
Update: Here's one that offers a preview function. From what I can see, it base64 encodes the local image and serves it to the surrounding HTML page as a inline data <img> tag. This is great because it might integrate well into your site. It does not work with any version of Internet Explorer, though.
Here's a fully Flash based solution that does previews in all browsers.
you first have to upload the document to server. Than you can show like.
<img src="uploads/file1_12224.jpg" />
The "file" input type doesn't expose the local file location of the file to be uploaded. It does "appear" to because as a user you can see the location, but the web page never knows this value. Without the local file address, you can't show a preview of the image on the web page using plain HTML or JavaScript.

Categories