Download image created by the PHP Exif Library from browser - php

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.

Related

FPDF exports .html instead of .pdf, only on Mac

I'm using the PHP library FPDF to generate PDFs on my website.
It works GREAT on all devices EXCEPT Mac. It saves a .html file instead of .pdf.
Even iPhones work perfectly.
Here is my code:
<?php
require('includes/fpdf/fpdf.php');
class PDF extends FPDF {}
$mypdf = new FPDF();
// Content of PDF begins
// [...]
// Content of PDF ends
$file = utf8_decode('test.pdf');
$mypdf->Output('F', 'includes/exports/'.$file);
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"". basename($file) ."\"");
readfile('includes/exports/'.$file);
exit(); ?>
Thank you for your help!
The only way to achieve it is by storing the PDF and showing a download link to the user. Good workaround

display pdf in browser using php

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

Cant download a SWF image or preview it using PHP

Hi Stackoverflow community,
I've been trying to download a swf image from a extern server, which you can reach by a simple url.
Sadly the downloaded SWF wouldn't show up in the browser, so i assume its a broken file. Also I'm not able to preview the SWF file through PHP.
I know I could embed the SWF but i kinda need a screenshot or a downloaded version of it.
Code I've tested to download the SWF to my server:
function save_swf(){
$swf_file = file_get_contents('http://assets.zwinky.com/assets3/avatar/avatar10.8.swf?u=' . $this->username);
file_put_contents(strtolower($this->award . '_' . $this->username . '.swf'), $this->swf);
}
Code which i used to check if the image can be previewn by PHP:
<?php
$data = #file_get_contents('http://assets.zwinky.com/assets3/avatar/avatar10.swf?u=dane');
header("content-type: application/x-shockwave-flash");
header("Content-Disposition: inline;" echo $data);
header("accept-ranges: bytes", true);
header("connection: keep-alive", true);
echo $data;
?>
Does anyone have a idea why it wouldn't work?
Basis SWF im trying to get the file from: http://assets.zwinky.com/assets3/avatar/avatar10.8.swf?u=dane
If you write the data to a file locally on the server, the following should work:
// Write swf file locally using file_put_contents();
$fileName = ""; // The filepath where you've written it to
header("Content-Type: application/x-shockwave-flash",true);
header("Content-Length: {strlen($fileName)}",true);
header("Accept-Ranges: bytes",true);
header("Connection: keep-alive",true);
header("Content-Disposition: inline; filename=$fileName");
readfile($fileName);
Let me know if you need any addition help with this.

Force download file that's not placed on the server

I'm trying to force download a pdf file that I'm generating. I don't need the pdf file to be actually saved on the server.
So when I generate my pdf file, I get the file content. I then encode it with base64. Now the problem is that I need to force download it. I've looked all over the web, but I haven't found any search results that tells me how to do this without the file actually being placed on the site.
I've tried the following code:
header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=\"invoice.pdf\"");
header("Content-Length: ".filesize($pdffile));
readfile(base64_decode($pdffile));
But, it's giving me a corrupt pdf file, (1 kb). The actual file should be around 50kb.
Any ideas, as to what I can try?
readfile trying to output content from file, but you have only data string. Try this instead:
header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=\"invoice.pdf\"");
echo base64_decode($pdffile);
I also suggest rename $pdffile to $pdfcontent for even better clarification.

PHP force download, Not working with variables

When
header('Content-disposition: attachment; filename=1330554893-COVER.jpg');
header('Content-type: jpeg');
readfile('watermarked/1330554893-COVER.jpg');
Is run in a file for example "testdownload.php" It downloads the image
"watermarked/1330554893-COVER.jpg"
and names it
"1330554893-COVER.jpg"
But when I try make the code dynamic to download different files.
header("Content-disposition: attachment; filename={$newFileName}");
header("Content-type: jpeg");
readfile("{$findFile}");
where
$newFileName = "1330554893-COVER.jpg" and $findFile = "watermarked/1330554893-COVER.jpg"
It downloads an image "1330554893-COVER.jpg" but it cannot be opened and I get an error "Windows Photo Viewer can't open this picture because eaither Photo Viewer doesn't support this file format"
Thanks for helping :)
Allrite then, don't use readfile(), try echo file_get_contents after the headers!

Categories