Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 days ago.
Improve this question
I am working on a WordPress Website, in which the admin can download the CV of users in PDF or Word Format
When I try to download CV, it randomly gives Network error.
ob_start();
header('Content-Description: File Transfer');
header('Content-Type: ' . $file_mimetype);
header("Content-type: application/force-download");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: Binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . #filesize($file_path));
ob_end_clean();
flush();
#readfile($file_path);
exit;
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
From Laravel official documentation:
For files stored using the s3 or rackspace driver, you may create a
temporary URL to a given file using the temporaryUrl method.
Is there any way to have temporary download url for files rather than using s3/etc and for local storage only. I am using https://github.com/spatie/laravel-medialibrary library for development.
public function downloadFileAction()
{
if (isset($_REQUEST['file_name'])) {
$pathFile = STORAGE_PATH.'/'.$_REQUEST['file_name'];
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.$_REQUEST['file_name'].'"');
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($pathFile));
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Expires: 0');
readfile($pathFile);
}
}
public function uploadFile(array $file)
{
$storagePath = STORAGE_PATH;
#mkdir($storagePath, 0777, true);
$fullPath = $storagePath. uniqid (time()). $file['name'];
$fileTemp = $file['tmp_name'];
move_uploaded_file($fileTemp, $fullPath);
return $fullPath;
}
In your controller, you can take file with this: $_FILES
First of all I ask for an apologize, I know this question had been asked and already been answered but I still can not figure out what to do.
I put my files outside and before of root directory and want to access it when a customer purchases a file. I know I can use this method for downloading but I want this to get the file and let me to send it into other page and there customer click on the link to download it and also mention that a customer may have purchased many files.
How can do the same for all files? Should I put them in a loop?
Here is my code:
<?php
$file = 'monkey.gif';
if (file_exists($file))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;
filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre- check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
Thanks in advance.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have physical files which I want users to download on my website. The files are located at:
C:/xampp/htdocs/myfile/uploads/*
I need a PHP script which can download files dynamically on click. Let's say I have the following button which when clicked it triggers magic.php script.
Download file
What PHP code do I need in magic.php to download the file name I passed in the query parameters?
Download link
Download
magic.php page
<?php
$file = 'C:/xampp/htdocs/myfile/uploads/'.urldecode($_GET['file']);
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>
Maybe you could do something like this: (Correct me if i am wrong)
<a href="uploads/<?php echo $row['name']; ?>" download="download">
This question already has answers here:
Download File to server from URL
(12 answers)
Closed 8 years ago.
I have a file with URL !
$url = "http://www.example.com/aa.txt";
and I want to download this file and save it to path on my website
this is my website ( online )
$path = "server/username/";
i want the $url file saved to $path ,,
i try this
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
?>
when I test the code , it make the file download to my computer not to my website
you can use file_put_contents();
see manual here:http://php.net/manual/en/function.file-put-contents.php
a different implementation here:http://www.finalwebsites.com/forums/topic/php-file-download
This question already has answers here:
Size not showing while downloading files from my website
(3 answers)
Closed 8 years ago.
Please see the screenshot below. When someone is downloading files from my site it, while downloading size is not showing. Thus, users cannot know how much is remaining, what is the size. Can someone help me or tell any idea to fix this? Is this a problem with the server? Or I have to put any code or something?
You should properly send the headers from your server
Better look at this :- http://php.net/manual/en/function.readfile.php
Example
<?php
$file = 'yourfile.apk';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>