After working on this Problem for several Days now i need to ask for help me.
I've made a simple scrpit for uploading CSV
in PHP
.
It's working fine on my Windows XAMPP so far.
While i moved the script to a Oracle linux server in my company i have a lot of charset issues. German umlauts like ö, ä, ü are displayed like ö, Ã...
function uploading($tmp,$name,$size,$type){
$target_dir = "import/";
$target_file = $target_dir . basename("".date('m-d-Y_H_i_s').".csv");
$uploadOk = 1;
// Check if image file is a actual CSV or fake
if(isset($_POST["submit"])) {
$mimes = array('application/vnd.ms-excel','text/plain','text /csv','text/tsv');
if(in_array($_FILES['fileToUpload']['type'],$mimes)){
$uploadOk = 1;
} else {
die("Sorry, mime type not allowed");
$uploadOk = 0;
}
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
import($target_file);
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
Here is the csv script with encoding to utf8
.
header("Content-Type: text/html; charset=utf-8");
if (($handle = fopen($csv_file, "r")) !== FALSE) {
fgetcsv($handle);
while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
$col[$c] = $data[$c];
}
//direct encode for testing
$col1 = utf8_encode($col[2]);
$col2 = utf8_encode($col[3]);
$col3 = utf8_encode($col[4]);
$col4= utf8_encode($col[1]);
$col5= utf8_encode($col[5]);
echo $col2;
echo $col1;
Th CSV
is in utf8
, default charset is utf8
, i added a header for content type in utf8
and i try to convert every string to utf8
and the encoding still doesn't work
Do you have any idea how to handle the German umlauts?