即時通訊從數組中生成一個CSV,但它會自動下載到一個臨時文件夾,有沒有一種方法可以定義下載文件的位置。CSV無法下載到特定的位置
while($finalRes = mysql_fetch_assoc($excute))
{
$tables[] = $finalRes;
}
function convert_to_csv($input_array, $output_file_name, $delimiter)
{
/** open raw memory as file, no need for temp files */
$temp_memory = fopen('php://memory', 'w');
/** loop through array */
$header = array("XXX","XX","XX","XX","XX","XX","XX","XX");
fputcsv($temp_memory, $header, $delimiter);
foreach ($input_array as $line) {
/** default php csv handler **/
fputcsv($temp_memory, $line, $delimiter);
}
/** rewrind the "file" with the csv lines **/
fseek($temp_memory, 0);
/** modify header to be downloadable csv file **/
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Transfer-Encoding: binary");
header('Content-Type: application/csv');
header('Content-Disposition: attachement; filename="' . $output_file_name . '";');
/** Send file to browser for download */
fpassthru($temp_memory);
}
convert_to_csv($tables, 'report.csv', ',');
人誰擁有大約產生並下載CSV文件 – 2015-01-21 06:39:51
您是否嘗試過使用'的fopen( 'FILE.CSV', 'W')的想法;'第一? – Rasclatt 2015-01-21 06:46:16
i dint嘗試一下..生病嘗試,然後 – 2015-01-21 06:53:57