I am letting users upload a file and i am storing the name of the original file name in one field and the other the renamed name of the file to avoid duplicates and other risks. So when i let them download it, i want them to be able to download it as the original name but when its on our servers i want to use the renamed version.
Sample:
$original = the name the user gave the file
$renamed = the name we gave the file
header('Content-type: application/octet-stream'); // concatenation
header("Content-disposition: attachment; filename=$original"); // double quotes
$filename="../../../../docs/doc/$renamed";
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($filename));
ob_clean();
flush();
readfile($renamed); // no quotes needed
i tried doing this but since the original name is stored in the database and the actual file name is the renamed one how can i achieve this?
1 Answer