문제
사용자 정의 모듈에서 파일을 만들고 drupal_goto
를 사용하여 다운로드하십시오.다운로드 한 후 파일을 어떻게 삭제할 수 있습니까?file_unmanaged_delete
가 실행되지 않으면 drupal_goto
를 배치하고 권한 검사를 위해 다운로드하기 전에 hook_file_download
가 발생합니다.그래서 나는 이것을하는 방법을 모르겠습니다.크론이있는 폴더에있는 파일을 청소하는 데 리소싱해야합니까?
올바른 솔루션이 없습니다
다른 팁
// Generate pdf card.
$file_path = $crm_card->generatePdfCard();
$filename = basename($file_path);
$headers = [
'Content-Type' => 'application/octet-stream',
'Content-Disposition' => 'attachment; filename="' . $filename . '"',
'Content-Length' => filesize($file_path),
];
$binary_file_response = new BinaryFileResponse($file_path, 200, $headers);
$binary_file_response->deleteFileAfterSend(TRUE);
return $binary_file_response;
. 다음 코드는 파일이 TMP 디렉토리에 있음을 고려하여 다운로드 한 후 파일을 제거합니다.
$filename = 'foobar.xls';
$temp_path = realpath(file_directory_temp()) . '/';
if (file_exists($temp_path . $filename)) {
// Serve file download.
drupal_add_http_header('Pragma', 'public');
drupal_add_http_header('Expires', '0');
drupal_add_http_header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0');
drupal_add_http_header('Content-Type', 'application/vnd.ms-excel');
drupal_add_http_header('Content-Disposition', 'attachment; filename=' . basename($temp_path . $filename) . ';');
drupal_add_http_header('Content-Transfer-Encoding', 'binary');
drupal_add_http_header('Content-Length', filesize($temp_path . $filename));
readfile($temp_path . $filename);
unlink($temp_path . $filename);
drupal_exit();
}
.
자세한 내용은 다음 링크를 방문 할 수 있습니다. http://kahthong.com/2012/08./ 간단한 방식 - 사용법 - Drupal-serv-File-Downloads
감사합니다!
제휴하지 않습니다 drupal.stackexchange