Hey Team, I need some help while downloading the uploaded files. I have a upload code on controlled with the function called add. and download code also in the same controller with fucntion name download. When i tried to download the file , it is not throwing any error and nothing is happening it just throws a blank white page. I tried it in debug mode also , still the same.
-------------------------------------------------- to upload file ---------------------------------------------------------------
if ($myidea[‘uploadFile’][‘name’] != “”) {
$target_dir = WWW_ROOT . "uploads/";
$target_file = $target_dir . basename($_FILES["uploadFile"]["name"]);
$fileType = pathinfo($target_file, PATHINFO_EXTENSION);
$bytes = filesize($_FILES["uploadFile"]["tmp_name"]);
$setNewFileName = time() . "_" . rand(000000, 999999);
$document = strtolower($_SESSION["Auth"]["User"][0]["firstName"] . "_" . $setNewFileName) . "." . $fileType;
$myidea["filename"] = $document;
$myidea["orginal_filename"] = $myidea["uploadFile"]["name"];
move_uploaded_file($myidea["uploadFile"]["tmp_name"], $target_dir . $document);
}
--------------------------------------------------- To download file ----------------------------------------------------------------
public function download($id){
$myideas = $this->Myideas->get($id);
$file_path = WWW_ROOT . ‘uploads’ . DS . $myideas->filename;
$this->log($file_path);
$this->response->withFile($file_path, array(
‘download’ => true,
‘name’ => $myideas->orginal_filename,
));
return $this->response;
}
------------------------------------------- Error that is shown ------------------------------------------------------------------
This is displaying… i couldn’t found where is the error. I just migrated from cakephp 3.4 to cakephp 4.5 and php 7.4 to php 8.1.