예제 #1
0
 public function Awsdownloadsinglefile($key, $filename = '', $userid, $downloadTokenValue = "")
 {
     try {
         $signedurl = $this->Awsdownloadfile($key);
         $url = $signedurl->signedUrl;
         $file = explode('/', $key);
         $rfile = fopen($url, 'r');
         $tempfile = $file[count($file) - 1];
         $tempfolder = public_path() . DIRECTORY_SEPARATOR . 'temp';
         $tempfolder = str_replace('\\', '/', $tempfolder);
         $tempfolder = str_replace('/', DIRECTORY_SEPARATOR, $tempfolder);
         is_dir($tempfolder) || mkdir($tempfolder);
         $tempUserFolder = $tempfolder . DIRECTORY_SEPARATOR . $this->GenerateFolderName($userid);
         is_dir($tempUserFolder) || mkdir($tempUserFolder);
         $tempfile = $tempUserFolder . DIRECTORY_SEPARATOR . basename($tempfile);
         $lfile = fopen($tempfile, 'w');
         while (!feof($rfile)) {
             fwrite($lfile, fread($rfile, 4095), 4095);
         }
         fclose($rfile);
         fclose($lfile);
         $fullPath = $tempfile;
         if (!$filename) {
             $filename = basename($fullPath);
         }
         setcookie("fileDownloadToken", $downloadTokenValue, time() + 3600, "/");
         setcookie("userSingleFileDownloadToken", $downloadTokenValue, time() + 3600, "/");
         setcookie("DownloadSingleRFI", $downloadTokenValue, time() + 3600, "/");
         setcookie("DownloadPlansRFI", $downloadTokenValue, time() + 3600, "/");
         setcookie("DownloadSpecsRFI", $downloadTokenValue, time() + 3600, "/");
         setcookie("DownloadSpecsSubmittal", $downloadTokenValue, time() + 3600, "/");
         setcookie("DownloadSubmittalFiles", $downloadTokenValue, time() + 3600, "/");
         $fileDetail = pathinfo($filename);
         $filedata = file_get_contents($fullPath);
         // Read the file's contents
         header('Content-Description: File Transfer; charset=UTF-8');
         $contentType = Common::GetFileContentType($filename);
         header('Content-Type: ' . $contentType . '');
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         header('Expires: 0');
         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
         header('Pragma: public');
         header('Content-Length: ' . filesize($fullPath));
         ob_clean();
         flush();
         readfile($fullPath);
         $parentDir = dirname($fullPath);
         unlink($fullPath);
         is_dir($parentDir) && rmdir($parentDir);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }