Im using PEL - the PHP Exif Library to add metadata to my image.
the script work well and i can do online view my image with browser.
$jpeg = new PelJpeg($inputfile);
$jpeg->setExif($exif);
header("Content-Type: image/jpeg");
echo $jpeg->getBytes();
but when i tried to download it, script did not work.
$jpeg = new PelJpeg($inputfile);
$jpeg->setExif($exif);
header("Content-Type: image/jpeg");
header('Content-Disposition: attachment; filename=nature.jpg');
Please help.
Thank you!
im trying to allow user download the file from browser but the file i got has 0 byte and said corrupted.
I run PDF file through localhost in php there is a option in browser of printing the PDF and I dont want it to be print.
Here is my code:
header('Content-type: application/pdf');
readfile('The C# 4.0 complete reference.pdf');
die();
kindly help me
try this code
<?php
header("Content-type:application/pdf");
// It will be called downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");
// The PDF source is in original.pdf
readfile("original.pdf");
?>
hi so im trying to display a pdf file in the browser using php so i used this code
<?php
$filename = "uploads/docs/Preamble and National Territory.pdf";
header("Content-type: application/pdf");
header("Content-Length: " . filesize($filename));
readfile($filename);
exit;
?>
i juat hardcoded the pdf file name but will change it later my problem is it does not load the pdf file in my browser here is what it says
any idea how to improve my code? or what im doing wrong? thanks in advance
I am using pdfcrowd to convert php file into pdf but it converts blank pdf. What may be the issue? Do pdfcrowd convert php file?
Code is here
<?php
require 'pdfcrowd.php';
try
{
$client = new Pdfcrowd("nabinashahi", "2ef55554fe4c2d23b52b8e080cac867g");// create an API client instance
// $pdf = $client->convertURI('http://www.google.com/');
$pdf = $client->convertFile("C:/xampp/htdocs/pdf/page.php");// convert a web page and store the generated PDF into a $pdf variable
// set HTTP response headers
header("Content-Type: application/pdf");
header("Cache-Control: no-cache");
header("Accept-Ranges: none");
header("Content-Disposition: attachment; filename=\"google_com.pdf\"");
echo $pdf;// send the generated PDF
}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why;
}
?>
I believe the problem is that you are not converting the output generated by your php file, but the actual php file itself. pdfCrowd is able to convert HTML into pdf - I don't think they handle php source code that well, and I don't think thats what you want to do :-)
I want to show my users PDF files. The reason why I use CGI to show the PDF is I want to track the clicks for the PDF, and cloak the real location of the saved PDF.
I've been searching on the Internet and only found how to show save dialog to the users and creating a PDF, not show the files to the users.
What I wanted for is show the users my PDF files, not creating or download the PDF.
Here is what I got form the official PHP documentation:
<?php
header('Content-type: application/pdf');
readfile('the.pdf');
?>
Also my google-search-result perl code:
open(PDF, "the.pdf") or die "could not open PDF [$!]";
binmode PDF;
my $output = do { local $/; <PDF> };
close (PDF);
print "Content-Type: application/pdf\n";
print "Content-Length: " .length($output) . "\n\n";
print $output
if you do it on ruby, please say it to me. But I'm not sure if my server support rails.
Sorry if my code is too far away from the method to show the pdf, since I don't know anything about pdf processing and how to implement this problem.
Lets assume that the users have the Adobe Reader plug-in. So, how to fix my problem?
edit : I want to show plain PDF file. My primary purpose: track my pdf files and use some fancy urls.
edit : Here's my main php code:
<?php
$file='/files/the.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
#readfile($file);
?>
edit : Now the code is working. But the loading progress bar (on Adobe Reader X plugin) doesn't shows up. Why? Anyone can help me? Here's my main code:
<?php
$file='./files/the.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
#readfile($file);
?>
edit : All my problems solved. Here's the final code:
<?php
$file = './path/to/the.pdf';
$filename = 'Custom file name for the.pdf'; /* Note: Always use .pdf at the end. */
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
#readfile($file);
?>
Thanks! :)
I assume you want the PDF to display in the browser, rather than forcing a download. If that is the case, try setting the Content-Disposition header with a value of inline.
Also remember that this will also be affected by browser settings - some browsers may be configured to always download PDF files or open them in a different application (e.g. Adobe Reader)
$url ="https://yourFile.pdf";
$content = file_get_contents($url);
header('Content-Type: application/pdf');
header('Content-Length: ' . strlen($content));
header('Content-Disposition: inline; filename="YourFileName.pdf"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');
die($content);
Tested and works fine. If you want the file to download instead, replace
Content-Disposition: inline
with
Content-Disposition: attachment
You could modify a PDF renderer such as xpdf or evince to render into a graphics image on your server, and then deliver the image to the user. This is how Google's quick view of PDF files works, they render it locally, then deliver images to the user. No downloaded PDF file, and the source is pretty well obscured. :)
The safest way to have a PDF display instead of download seems to be embedding it using an object or iframe element. There are also 3rd party solutions like Google's PDF viewer.
See Best Way to Embed PDF in HTML for an overview.
There's also DoPDF, a Java based In-browser PDF viewer. I can't speak to its quality but it looks interesting.
You can also use fpdf class available at: http://www.fpdf.org.
It gives options for both outputting to a file and displaying on browser.
There is a simple solution using the embed tag:
<span class="fileShow">
<a href="aa.pdf" onclick="event.stopPropagation();" target="_blank">
<embed style="width:450px; height:300px; max-width:450px; max-height:300px" src="aa.pdf">
</a>
</span>