Problem with the fgetcsv() in php
I have the following piece of code to parse a csv file. After that I am displaying it. The .csv file is displaying perfectly on my local machine but on the server after clicking on upload a blank page is displaying.
function uploadTrainees()
{
$csv = array();
$tmpName = $_FILES['csv']['tmp_name'];
//echo $tmpName;
//ini_set('auto_detect_line_endings',true);
$fp = fopen($tmpName,'r');
$fields = array('delegate_title', 'delegate_firstname', 'delegate_lastname', 'delegate_jobtitle', 'dele开发者_运维知识库gate_email', 'delegate_phone', 'is_bringing_own_laptop');
$records = array();
while ($record = fgetcsv($fp,1000,','))
{
$records[] = array_combine($fields, $record);
}
fclose($fp);
}
Help me to solve this issue.
What version of PHP is the live server running?
The function array_combine()
is only in PHP5
Edit
There is a function here to do this - http://snipplr.com/view/4918/arraycombine-for-php4/
if (!function_exists('array_combine'))
{
function array_combine($arr1,$arr2) {
$out = array();
foreach ($arr1 as $key1 => $value1) {
$out[$value1] = $arr2[$key1];
}
return $out;
}
}
精彩评论