wordpress php download pdf adds page html to front of file - php

This used to work on my old hosting service. I just migrated to websynthesis and now when I download pdf files through browser, the html code for the download page is added to the pdf. The pdf file generated is ok when I download it directly, but not when downloaded through a browser. I am using the standard download script:
session_start();
header("Content-disposition: attachment; filename=$_SESSION[myfile.pdf]");
header("Content-type: application/pdf");
readfile($_SESSION[download-file.pdf]);
I have tried using many additional or alternate header statements with no success. Is there some additional header info I need to add?
Also filed support ticket with websynthesis

Related

Force iPad to download a CSV file

I have a web app in which some data is being exported and imported through CSV files. The users don't really have any meaning from opening them directly, so I'm forcing the browser to download the file, so they can save or forward the data to someone else.
I am using the following headers (in PHP):
header("Content-Type: text/csv");
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"name.csv\"");
This seems to work on PC's and phones (Android and Windows phone), but it doesn't work on iPads. iPad always shows the contents, and then doesn't offer any forward or share options (except opening or sharing the link to the page, which wouldn't work because you'd have to be logged in).
Can I force iPad to download it, or at least offer the option to attach the CSV file in a new email?

Empty lightbox when pdf confugered save file in firefox

I am using joomla 2.5 with ROXBOX plugin and using this showing the PDF's in lightbox. I am facing problem when user configured Firefox auto download PDF files.
When Firefox configured as save PDF instead of open it in browser the light box stays blank and file started download. As we can not have control on browser, is there any way show any message when Firefox auto download for PDF is enabled?
Please Help!!
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. and 'Content-type to application/pdf.
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
You can use PHP to set header as shown above.

Rename function to move a file between folders does not work properly

header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);`
Here is my code to download an audio file.
It was successful and the file is saved to system downloads folder.
Now I want to have an application specific download folder and save all downloaded music files to that folder only so that I can use directory listing to show all those downloads.
I tried coding like:
rename('C:\Users\user2\Downloads/'.$file,
'C:\Users\user2\Music\Playlists/'.$file);
But it's not working all the time.
Any Help is Appreciated.
modify your code as shown, since you are working on windows machine, pls change the slash
rename("C:\Users\user2\Downloads\$file", "C:\Users\user2\Music\Playlists\$file");

Send PDF file from PHP to android app

I am generating PDF file dynamically in PHP and I have to output that PDF file in my android app I am developing. I have to output and display that PDF file. The problem is that I don't know how to send that PDF file from the PHP to the android app and how to make the android app open the PDF?
There are only two ways to output a PDF in a browser; inline and attachment.
In PHP set your content disposition, filename, and content type:
header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=myfile.pdf");
or
header("Content-disposition: inline; filename=myfile.pdf");
then echo the contents of the pdf as a string.
In your app, if you have a broswer window pointed to the url, the file should open up in whatever you've set your default PDF viewer to be. Or if you're using the inline disposition, it may open up right in the application.

Javascript/Jquery: download multiple images and save locally

I created in php starting with file_get_content to load a HTML page, parse to DOM and using xpath to find all image tags by class name. Essentially in the end I can resize and save all images locally(because I try on localhost).
The thing is once I hosted my php, all images will be saved on the server. The other solution might be to ask the user to install (e.g xampp) to run it locally (but not a preferable solution).
Could I do the same method with javascript/jquery to save all images found in a page? All I know is javascript can save but has to pop-up dialog save as and that also require to be done one by one for each image.
Thanks in advance for any answer.
You can't send multiple individual files. Best bet is to use the zip extension to compress multiple files together and offer that for download.
Zip Extension
You don't need to use JavaScript, you can use PHP to force the image download:
$file = 'path/to/image.png';
header('Content-Description: File Transfer');
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename= ".$file."");
readfile($file);

Categories