I have a controller method that is supposed to force-download an asset uploaded via backend. The method recieves the ID of such asset and uses SS_HTTPRequest.
The problem is that although i can directly access the asset in the template via $File.URL I can't read it via php because file_exists says $File.URL does not exists.
This is the method source
public function download(){
$assetID = $this->request->param('ID');
$do = DataObject::get_by_id('File', $assetID);
if($do && file_exists($do->URL)){
return SS_HTTPRequest::send_file(file_get_contents($do->URL), $do->Name);
}else{
echo 'error with ' . $do->URL . ' (' . file_exists($do->URL) . ')';
return false;
}
}
Am I missing something here?
Thanks in advance