I want to create a file download function in PHP [Closed]

Asked 2 years ago, Updated 2 years ago, 48 views

Do you want to improve this question?Edit this post and update the question to focus on one issue

Closed 7 years ago.

7 years ago

As the title says, I was able to create a file upload function, but I cannot create a download function.
I would like to ask anyone who has experience to teach me.(The framework uses cakePHP)

php cakephp

2022-09-30 18:17

2 Answers

Rather than cakephp, I think it's a normal php problem.
Create a php like the one below and link from html.

<?php
$file="test.txt";
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$file");
readfile($file);
exit;
?>


2022-09-30 18:17

There are two ways to do something like cake:
With this method, you don't have to write the response header yourself, so
It might be comfortable.

http://qiita.com/madiehak/items/9b104be97c4c37a3465d
http://www.php-kaihatsu.com/blog/649.html


2022-09-30 18:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.