diff --git a/application/helpers/admin/import_helper.php b/application/helpers/admin/import_helper.php index e1ce046e620..34618269ba6 100644 --- a/application/helpers/admin/import_helper.php +++ b/application/helpers/admin/import_helper.php @@ -2111,19 +2111,15 @@ function TSVImportSurvey($sFullFilePath) $file = stream_get_contents($handle); fclose($handle); - // fix Excel non-breaking space $file = str_replace("0xC20xA0",' ',$file); // Replace all different newlines styles with \n $file = preg_replace('~\R~u', "\n", $file); - $filelines = explode("\n",$file); - $row = array_shift($filelines); - $headers = explode("\t",$row); - $rowheaders = array(); - foreach ($headers as $header) - { - $rowheaders[] = trim($header); - } + $tmp = fopen('php://temp', 'r+'); + fwrite($tmp,$file); + rewind($tmp); + $rowheaders = fgetcsv($tmp,0,"\t",'"'); + $rowheaders = array_map('trim',$rowheaders); // remove BOM from the first header cell, if needed $rowheaders[0] = preg_replace("/^\W+/","",$rowheaders[0]); if (preg_match('/class$/',$rowheaders[0])) @@ -2132,12 +2128,9 @@ function TSVImportSurvey($sFullFilePath) } $adata = array(); - foreach ($filelines as $rowline) - { + while (($row = fgetcsv($tmp,0,"\t",'"')) !== FALSE) { $rowarray = array(); - $row = explode("\t",$rowline); - for ($i = 0; $i < count($rowheaders); ++$i) - { + for ($i = 0; $i < count($rowheaders); ++$i) { $val = (isset($row[$i]) ? $row[$i] : ''); // if Excel was used, it surrounds strings with quotes and doubles internal double quotes. Fix that. if (preg_match('/^".*"$/',$val)) @@ -2148,7 +2141,7 @@ function TSVImportSurvey($sFullFilePath) } $adata[] = $rowarray; } - + fclose($tmp); $results['defaultvalues']=0; $results['answers']=0; $results['surveys']=0; diff --git a/application/third_party/pclzip/pclzip.lib.php b/application/third_party/pclzip/pclzip.lib.php index c0ef61681d1..515adde8dd8 100644 --- a/application/third_party/pclzip/pclzip.lib.php +++ b/application/third_party/pclzip/pclzip.lib.php @@ -1837,14 +1837,17 @@ function privOptionDefaultThreshold(&$p_options) $v_memory_limit = trim($v_memory_limit); $last = strtolower(substr($v_memory_limit, -1)); - if($last == 'g') + if($last == 'g') { //$v_memory_limit = $v_memory_limit*1024*1024*1024; $v_memory_limit = $v_memory_limit*1073741824; - if($last == 'm') + } + if($last == 'm') { //$v_memory_limit = $v_memory_limit*1024*1024; - $v_memory_limit = $v_memory_limit*1048576; - if($last == 'k') + $v_memory_limit = ((int) $v_memory_limit) * 1048576; + } + if($last == 'k') { $v_memory_limit = $v_memory_limit*1024; + } $p_options[PCLZIP_OPT_TEMP_FILE_THRESHOLD] = floor($v_memory_limit*PCLZIP_TEMPORARY_FILE_RATIO);