0

I worte an api where I need to check if file is not older than 5 seconds before download.

I think it might be problem with routing but it throws:

"Warning: filemtime(): stat failed for {req}"

and $req should be my .csv file in specific location.

My code:

/**
 * @Route("/uploads/{date}/{req}", name="export", requirements={"req"=".*"})
 * @ParamConverter("date", options={"format": "Y-m-d"})
 */
public function getTransactionExportToCsvAction($req)
{
    $file = $req;

    $projectDir = $this->get('kernel')->getProjectDir() . '/protected/uploads/'  . date('Y-m');

    $fullPath = $projectDir . '/' . $file;

    $pathDir = dirname($fullPath);

    if(!is_dir($pathDir)) {
        mkdir($pathDir, 0777, true);
    }

    $time = 5; //seconds

    if( time() - filemtime( $file ) <= $time )
    {
       return $pathDir;
    }
    else
    {
        throw new \Exception('File does not exist!');
    }

}
develops
  • 279
  • 1
  • 5
  • 14

0 Answers0