my controller looks this:
public function download($filepath) { // generate response $response = new response(); // set headers $response->headers->set('cache-control', 'private'); $response->headers->set('content-type', mime_content_type($filepath)); $response->headers->set('content-disposition', 'attachment; filepath="' . basename($filepath) . '";'); $response->headers->set('content-length', filesize($filepath)); // send headers before outputting $response->sendheaders(); $response->setcontent(readfile($filepath)); }
passing filepath results in following error message:
call undefined function mybundle\controller\mime_content_type()
how can solve problem?
try use file class
$ofile = new file($filepath); $response->headers->set('cache-control', 'private'); $response->headers->set('content-type', $ofile->getmimetype()); $response->headers->set('content-disposition', 'attachment; filepath="' . $ofile->getbasename() . '";'); $response->headers->set('content-length', $ofile->getsize());
i have not tested running code. hope works fine. don't forget add
use symfony\component\httpfoundation\file\file;
statement @ top of file.
hope helps.
Comments
Post a Comment