在 php 中使用 fputcsv 时无法访问此站点错误



文件下载代码后,我在XAMPP收到错误 无法访问此网站位于 http://localhost/aiken/index.php/admin/view_download 的网页可能暂时关闭,或者可能已永久移动到新的网址。 ERR_INVALID_RESPONSE

function view_download()
{
if(isset($_POST['submit']))
{
$start_date = date("Y-m-d", strtotime($this->input->post('start_date')));
$end_date = date("Y-m-d", strtotime($this->input->post('end_date')));
$auditor = $this->input->post('auditor_name');
$model = $this->input->post('model');
$processor = $this->input->post('processor');
$grade = $this->input->post('grade');
$this->load->model('admin_crud');
$data['data'] = $this->admin_crud->search_dynamic($start_date, $end_date, $auditor, $model, $processor, $grade);
//export data in CSV File
// file name 
$filename = 'Search_'.date('Ymd').'.csv'; 
header("Content-Description: File Transfer"); 
header("Content-Disposition: attachment; filename=$filename"); 
header("Content-Type: application/csv; ");
// get data 
$usersData = $this->Crud_model->search_dynamic();
// file creation 
$file = fopen('php://output','w');
$header = array(
'Gulf_ID', 'AssetTag', 'SerialNumber', 'PartNumber', 'Manufacturer', 'Model', 'BoardTest', 'Processor', 
'ProcGen', 'ProcSpeed', 'RAM', 'Storage1Size', 'Storage1Type', 'StorageSmart', 'StorageHealth', 'Optical', 'Webcam', 'LAN',
'WIFI', 'Keyboard', 'FingerPrint', 'TrackPoint', 'Keyb.BackLight', 'BatteryTest', 'BatteryHealth', 'GRADE', 'COA', 'VideoCard', 
'VideoCard2', 'VideoMemory', 'Resolution', 'TouchScreenStatus', 'MADEIN', 'ObservNotes', 'Expanded Codes 1st Audit', 
'Expanded Codes 2nd Audit', '1st Audit Date', '2nd Audit Date', '1st Audit User', '2nd Audit User', 'Location', 'LaptopColour', 
'HwID', 'LANMACAdr', 'UnitID'
);
fputcsv($file, $header);
foreach ($usersData as $key=>$line){ 
fputcsv($file,$line); 
}
fclose($file); 
$data['title'] = 'Dynamic Search';
$data['render'] = 'list_aiken';
$this->load->view('layouts/layout', $data); 
}
else
{
redirect(base_url() . 'index.php/admin/search_dynamic');
}

}

我在php中使用fputcsv时遇到了同样的问题。

在我的例子中,标题数组的大小(在本例中为$header)与推送到每一行的数组的大小不同(在本例中为$line)。

您可以使用 PHP 的 sizeof 运算符来检查数组的大小。

相关内容

  • 没有找到相关文章

最新更新