简体   繁体   English

TYPO3:后端文件下载

[英]TYPO3: File download in Backend

I would like to integrate a CSV download in the Backend.我想在后端集成 CSV 下载。 The CSV file doesn't have to be saved on the server, so just a simple Array-to-CSV for download. CSV 文件不必保存在服务器上,因此只需一个简单的 Array-to-CSV 即可下载。

I know using FAL is quite tedious in TYPO3 so I would like to know if there is a simple solution for my issue.我知道在 TYPO3 中使用 FAL 非常乏味,所以我想知道是否有针对我的问题的简单解决方案。 Like calling a "download" action an returning a "CSV string" to download ?就像调用“下载”操作并返回“CSV 字符串”来下载?

I did used this solution for the download action but I am looking for a solution without FAL and without keeping the file on the server.我确实将这个解决方案用于下载操作,但我正在寻找一种没有 FAL 且不将文件保留在服务器上的解决方案。

No need for FAL or saving a file on the server.不需要 FAL 或在服务器上保存文件。 You can add a custom action in your controller that sets the content-type and disposition headers to treat your request like a download:您可以在控制器中添加一个自定义操作,设置内容类型和处置标头以将您的请求视为下载:

public function exportAction()
{
    // Just an example on how you could access the downloadable data.
    $records = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', 'tx_domain_model_table');
    // modify the result to be a csv encoded string, json or whatever you want it to be.
    $data = myConvert($records, 'csv');

    header('Content-Type: text/x-csv');
    header('Content-Disposition: attachment; filename="download.csv"');
    header('Pragma: no-cache');

    return $data;
}

Where $data equals a csv encoded array for example.例如,其中$data等于一个 csv 编码的数组。

What's more interesting is what kind of data you want to be downloadable.更有趣的是你想​​要下载什么样的数据。 To make your data downloadable, setting the header() 's and returning any simple data type should work.为了使您的数据可下载,设置header()并返回任何简单的数据类型应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM