I have a database on a web server, it has binary files stored in it, I need to download these files to the server directory, then change from bin to a PHP extension to capture data that appears in character blocks, I can do the whole process manually but I need to automate it, I don't know if it is possible to download files from the DB to the server's directory, or change its extension using PHP, I want to avoid discussions about the binary file, the focus is on these two questions if it is possible or not using PHP.
I know that there is this code to download from the server directory to the client, but I can't find a download from the DB to the server directory.
<?php
if(!empty($_GET['file'])){
$filename = basename($_GET['file']);
$filepath = 'downloads/' . $filename;
if(!empty($filename) && file_exists($filepath)){
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/zip");
header("Content-Transfer-Emcoding: binary");
readfile($filepath);
exit;
}
else {
echo "This File Does not exist.";
}
}