RGuillermo
asked on
PHP-MYSQL
Hi Experts,
I have many users accesing our site.
Each user has personal files.
We want to let each user ee only their files and let them download.
Any suggestions on how to let a file be downloaded.
Never done this before.
Regards,
I have many users accesing our site.
Each user has personal files.
We want to let each user ee only their files and let them download.
Any suggestions on how to let a file be downloaded.
Never done this before.
Regards,
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
replace the filenames accordingly instead of PDF.
I just realised my code was incomplete!
you should add the following for managing the download:
$download_size = strlen($dataStream);
header("pragma: public");
header("expires: 0");
header("Cache-Control: private");
header("Content-type: application/octet-stream") ;
header("Content-Dispositio n: attachment; filename=$fileDownload");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
echo $dataStream;
you should add the following for managing the download:
$download_size = strlen($dataStream);
header("pragma: public");
header("expires: 0");
header("Cache-Control: private");
header("Content-type: application/octet-stream")
header("Content-Dispositio
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
echo $dataStream;
For PDF:-
If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.
<?php
if(VALID_USER) {
switch( $ext ){
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword
case "xls": $ctype="application/vnd.ms
case "ppt": $ctype="application/vnd.ms
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-
}
header('Content-type: $ctype');
header('Content-Dispositio
readfile('original.pdf');
}
else {
echo "Invalid user";
exit();
}
?>
For more, read:-
http://www.php.net/manual/en/function.header.php