I have a site which allows clients to download files that they have purchased.
A link is sent to the customer which directs them to a page which checks if the link is valid, and if it is, allows them to download their product.
Here is an example of the link: http://www.psptubestop.com/dl/2z129a2.php?reference=6d556bde201a2fe4079874168&password=535864380ee2bc0f57cced3fe&pid=402
A lot of customers are saying that when they download, the .zip extension is missing, and I can't find the problem, it works fine on my machine, except when I do "save as", but even then some people are having problems.
Is there any way to allow them to download the file, and keep the .zip extension even if they press "save as"?
This is the code I am using to redirect them to the download...
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$originalfilename");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
Thanks for any help.
The problem could be that some files have spaces, in that case with your current code only the first part is used so loosing the extension part, to prevent such error you have to enclose the filename in double quotes, like so:
header('Content-Disposition: attachment; filename="'.$originalfilename.'"');
I am willing to bet it has something to do with there being a space in the filename seeing as the filename in the headers is PSP_Tubes_PSP_Tubes_Lisa_Cree_The Gift_6932.zip and the file wants to be save as PSP_Tubes_PSP_Tubes_Lisa_Cree_The.
Add a dummy GET parameter that looks like a filename.
...&fname=/foo.zip
Related
I am trying to download a remote pdf file in codeigniter which is password protected. Actually i have the username and password for the file, but i need to download the file directly without prompting by asking username and password for viewing it.I was trying with the below code in controller, but i am not sure that i tried correctly or not.
Actually, downloading is happening, but after opening the file its showing 'Failed to load PDF document'.
One more thing, i dont have a pre idea about the filename of the file to be downloaded, one file should be there corresponding to a cart id. So i am not sure whether the line header("Content-disposition: attachment; filename=tickets.pdf"); i used in below code is correct or not. I supposed it must be our custom file name for the file to be downloaded.
Below is the code in controller.
function file_download(){
$cart_id = $this->uri->segment(3);//Getting cart id from the url
$ticket_url=Base_url.'carts/'.$cart_id.'/tickets';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=tickets.pdf");
ob_clean(); flush();
readfile($ticket_url);
exit();
}
Thanks in advance!
I have an Adobe Illustrator file (AI) that we currently have a link to on a website which then downloads the file to your computer.
The link looks something like this...
http://domain.com/crm/index.php?entryPoint=fileupload_download&id=22440435-e8ee-bd6f-7612-533b2cd7690f&field=fuaifile_c&type=D1_Designs
What I need to do is rename this file as it downloads.
So I am asking if it is possible to pass this download through another PHP file right before it downloads which would allow me to change the filename on the fly that the user downloads. I cannot change the filename on the server but when it downloads I would like to be able to add some ID numbers to the filename on the fly if this is possibble? Any ideas how to accomplish this without having to resave the image on the server with a new name?
What you are looking for is the Content-Disposition header, as specified in RFC 2183:
Content-Disposition: attachment; filename=example.ai
You can set this header using the PHP header() function.
It's ugly, and assumes these aren't "large" files that would exceed your memory_limit, but
$data = file_get_contents($original_url);
header('Content-disposition: attachment; filename="new name with id numbers');
header("Content-type: application/octet-stream");
echo $data;
You could always enhance this to do byte serving - suck 10k from original url, spit out 10k to user, etc...
Just set the Content-Disposition:
header('Content-Disposition: attachment; filename="downloaded.pdf"');
(Example taken from PHP docs: http://www.php.net/manual/en/function.header.php).
Adding id:
$id = generateIdFromSomewhere();
header('Content-Disposition: attachment; filename="downloaded'.$id.'.pdf"');
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.
I have a pictrures gallery on my server. The pictures are stored on diffrent external servers. On my server are placed the thumbnails only.
How I can make a button "save as" in php so that a user can download a big picture file which is from external servers. I need a simple php script which can do download a jpg file cross all browser agents and from diffrent external servers. The button will be implemented inside html code. The button is a regular link formated in css style.
So how to do it properly. Thanks.
I would like also that the path of file should be send as a variable parameter to php script somehow.
I am guessing you are trying to have the pictures be downloaded automatically (you want a dialog box to pop up prompting where to save the file).
There is a great tutorial on this site that uses the php header function to force download
Check it out: http://www.ryboe.com/tutorials/php-headers-force-download
I found some solution with following php script
<?PHP
// Define the path to file
$file = $_GET['file'];
$name = basename ($file);
if(!file)
{
// File doesn't exist, output error
die('file not found');
}
else
{
// Set headers
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$name");
header("Content-Type: image/jpg");
header("Content-Transfer-Encoding: binary");
// Read the file from disk
readfile($file);
}
?>
and I can send parameters like url address cross html code
download
The only problem is that it is not working with all servers. It's not woriking for exemple with that file
http://backalleypics.com/Pictures/Letter Je~Ju/Jessica Alba/Jessica Alba 230.jpg
I don't know what I need to do?
Remove the spaces from your file name:
change: http://backalleypics.com/Pictures/Letter Je~Ju/Jessica Alba/Jessica Alba 230.jpg
to: http://backalleypics.com/Pictures/Letter_Je~Ju/Jessica_Alba/Jessica_Alba_230.jpg
I wanted to let a user download a file by simply clicking a button. Thing is, the file doesn't actually exist - its just some dynamic content.
So lets say:
$('a.download').click(function(){
$.post('get.php');
})
and in my PHP:
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=something.txt");
header("Content-Type: text");
header("Content-Transfer-Encoding: binary");
echo 'abcbdefg'
Is that valid? Is there some other way to do it?
Just create a link to the file, like this:
download my file
Whenever there's a request for a file of type PHP, your webserver will first process the file and output whatever text it contains to the client; you don't have to do anything special just because it's dynamic.
Using $.post() doesn't make sense for what you want to do; that POSTs data to the url you specify, it doesn't prompt the user to save a file.
Yeah, that's valid. I'm pretty that's the best way to do it.