This question already has answers here:
Prompt user to save file to a specific location
(4 answers)
Closed 6 years ago.
Here I am generate the dot RTF file for $report_content content.
It's successfully generated dot RTF file.
No need file download option and I want to move some location.
How to do?
<?php
//load the rtf template as a string
$email_id = 'ram#gmail.com';
$file_dir = 'uploads/';
$report_content = "
<html>
<body>
Hello, This is testing<br /><br />
message.
</body>
</html>";
//and now serve the file as an rtf download:
echo $report_content;
header("Content-type: application/rtf");
header("Content-Disposition: attachment;filename=rtf.rtf"); //How to save in $file_dir
exit();
Please update any other ways.
1)its not possible due to security issue.
2)you have to suggest the user to save particular location
Related
This question already has answers here:
Make multiple files to force-download
(4 answers)
Closed 4 years ago.
I have a problem.
I want to download multiple images form urls to visitor device. I dont need to zip the files. Just download one by one
This is my code :
$files = array(
'https://example.com/image.jpg',
'https://example.com/image2.jpg',
'https://example.com/image3.jpg'
);
foreach($files as $file)
{
$filename = 'images.jpg';
function forceDownload($filename, $type = "image/jpeg") {
header('Content-Type: '.$type.'; charset=utf-8');
header('Content-Disposition: attachment; filename="'.$filename.'"');
}
forceDownload($filename, "image/jpeg");
echo file_get_contents($file);
}
Thanks
You cant, HTTP doesn't provide a mechanism for sending multiple files over one request.
the only sensible way you can do this is to zip the images up into one zip file and download that.
OR...
display the images on the page and have a download button for each one individually I suppose.
Also your code is wrong, you are setting the file name to images.jpg and declaring a function every time you loop through the foreach loop.
This question already has answers here:
PHP generate file for download then redirect
(11 answers)
Closed 9 years ago.
I use the following code to download an xml file
<?php
header('Content-type: text/xml');
header('Content-Disposition: attachment; filename="download.xml"');
echo simplexml_load_file('temp.xml');
unlink('temp.xml');
?>
I would like to redirect to index.php after this. How do I do this?
header('location...) and meta refresh do not work
Well because you send the header and content this can't be done.
You have to redirect first and then let the file download on the target site.
Make your website change the url two times with javascript:
<script>
location.href="your_php_file_that_downloads_xml.php";
location.href="/other/site";
</script>
This question already has answers here:
A PHP script to let users download a file from my website without revealing the actual file link in my website?
(4 answers)
Closed 9 years ago.
I want to make images shopping site in which I want people buy images then they can download them.
My problem is how to create hidden path to image that people download the image and don't know the real path of the image.
You can call a php file to download the image and not the real image/path.
Like this you can call the real path inside your php file with something like:
$path = "/public_html/yourPath/";
if (! isset($_GET['img'])) {
die("Invalid URL");
}
$imageName = filter_var($_GET['img'], FILTER_SANITIZE_STRING);
$finalPath = $path.$imageName;
header('Content-type: octet/stream');
header('Content-Type: image/jpg');
header("Content-Disposition: attachment; filename=$finalPath;");
readfile($finalPath);
You can read more about it here.
Store the images in an offline location (not www) and retreive them with PHP, so they can access the image for example like this: http://yoursite.com/index.php?file=filename and then PHP will go and return that file from the offline location. You just need to set the correct headers so the content is not treated like a web page but an image instead. Now obviously, such link is still public so you need to add some more information to it to authenticate the downloader.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP - send file to user
I have written a script that successfully outputs userdata to a CSV file on my server.
My question: is there a way to make the CSV file popup so the user can open it? As is, the only way to open the file is directly from the server.
<?php
$csv_file = '/path/to/yourfile.csv'; // path to the csv file you're generating on the server
header('Content-type: text/csv');
header('Content-Disposition: attachment; filename="'.basename($csv_file));
readfile($csv_file);
?>
This question already has answers here:
How to Automatically Start a Download in PHP?
(5 answers)
Closed 7 years ago.
I have a php function for getting info out of my database. When they go to http://example.com/test/download
I want to create a fake test.txt (text is dynamic) and download it. It's contents should be the equivalent of executing foreach(databaseContent() as $content) { echo $content . '<br/>' } inside of it.
How can I get started on this? (Using php)
You can link to a php document along these lines, which forces a download of type plain text. (Well, suggests to the browser that that should happen, at any rate.)
<?php
header('Content-disposition: attachment; filename=gen.txt');
header('Content-type: text/plain');
echo "this is the file\n";
echo " you could generate content here, instead.";
?>
Of course, pass in appropriate post or get args, to control it the way you like.