<?php
echo "<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
//moguce greske
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_FILES['uploadFile']['name'];
$tmpName = $_FILES['uploadFile']['tmp_name'];
$error = $_FILES['uploadFile']['error'];
$size = $_FILES['uploadFile']['size'];
switch ($error) {
case UPLOAD_ERR_OK:
$valid = true;
//validate file extensions
$valid = false;
$response = 'Nedozvoljen tip datoteke.';
echo $response;
}
//validate file size
if ( $size/1024/1024 > 2 ) {
$valid = false;
$response = 'File size is exceeding maximum allowed size.';
}
//upload file
if ($valid) {
// $targetPath = dirname( __FILE__ ) . DIRECTORY_SEPARATOR. 'uploads' . DIRECTORY_SEPARATOR. $name;
// move_uploaded_file($tmpName,$targetPath);
// header( 'Location: index.php' ) ;
// exit;
$response = 'Datoteka je ucitana.';
}
break;
case UPLOAD_ERR_INI_SIZE:
$response = 'Velicina datoteke je veca od dozvoljene.';
break;
case UPLOAD_ERR_PARTIAL:
$response = 'The uploaded file was only partially uploaded.';
break;
case UPLOAD_ERR_NO_FILE:
$response = 'Datoteka nije ucitana.';
break;
case UPLOAD_ERR_NO_TMP_DIR:
$response = 'Nedostaje TMP folder. Introduced in PHP 4.3.10 and PHP 5.0.3.';
break;
default:
$response = 'Nepoznata greska';
break;
}
echo $response."<br>";
echo "informacije o datoteci:";
echo "<li>ime: ".$name."</li>";
echo "<li>tmpName: ".$tmpName."</li>";
echo "<li>greska: ".$error."</li>";
echo "<li>velicina: ".$size."</li>";
echo "<li>nastavak: ".$ext."</li>";
}
//stavljamo cijelu datoteku u matricu
$file = fopen($_FILES['uploadFile']['tmp_name'], 'r');
while (($result = fgetcsv($file)) !== false){
$csv[] = $result;
}
$ukupnoRedova=count($csv);
echo "<br>CSV datoteka je ucitana u matricu<br>";
echo "<li>ukupno redova: ".$ukupnoRedova."</li>";
echo "<li>max. kolona: ".$ukupnoKolona."</li>";
echo "<br>Ispis matrice u tabeli";
echo '<tbody><table border="1">';
for ($row = 1; $row < $ukupnoRedova; $row++) {
echo "<tr>";
for ($col = 0; $col < $ukupnoKolona; $col++) {
//ako celija nema vrijednost onda upisemo null da ne pise Undefined offset:
if ( ! isset($csv[$row][$col])) {
$csv[$row][$col] = null;
}
echo "<td>".$csv[$row][$col]."</td>";
}
echo "</tr>";
}
echo '</table></tbody>';
ini_set('auto_detect_line_endings',FALSE);
?>