実際のソースの場所を提供せずにユーザーにファイルを提供する、ある種のプロキシ PHP スクリプトを使用します。
ユーザーには、 http: //yourdomain.com/download.php?file=mydoc.docxが表示されます。
実際のパスはまだ /documents/userid/2342/mydoc.docx またはあなたの構造がどのように見えるかです。
次に、download.php ファイルがファイルを提供するようにします。
<?php
// Validate the user here
// Set document root
$root = 'documents/userid/'.$userID.'/';
// Requested file
$file = $_GET['file'];
// Validate
if (file_exists($root . $file))
{
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"".basename($file)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($root . $file));
ob_clean();
flush();
readfile($root . $file);
}
else { echo "File not found"; }
?>
詳細はこちら