"; //moguce greske error_reporting(E_ALL); ini_set('display_errors', 1); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_FILES['uploadFile']['name']; $tmpName = $_FILES['uploadFile']['tmp_name']; $error = $_FILES['uploadFile']['error']; $size = $_FILES['uploadFile']['size']; $ext = strtolower(pathinfo($name, PATHINFO_EXTENSION)); switch ($error) { case UPLOAD_ERR_OK: $valid = true; //validate file extensions if ( !in_array($ext, array('csv')) ) { $valid = false; $response = 'Nedozvoljen tip datoteke.'; echo $response; exit; } //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."
"; echo "informacije o datoteci:"; echo "
  • ime: ".$name."
  • "; echo "
  • tmpName: ".$tmpName."
  • "; echo "
  • greska: ".$error."
  • "; echo "
  • velicina: ".$size."
  • "; echo "
  • nastavak: ".$ext."
  • "; } //stavljamo cijelu datoteku u matricu $csv = array(); $file = fopen($_FILES['uploadFile']['tmp_name'], 'r'); while (($result = fgetcsv($file)) !== false){ $csv[] = $result; } fclose($file); $ukupnoRedova=count($csv); $ukupnoKolona= max( array_map( 'count', $csv ) ); echo "
    CSV datoteka je ucitana u matricu
    "; echo "
  • ukupno redova: ".$ukupnoRedova."
  • "; echo "
  • max. kolona: ".$ukupnoKolona."
  • "; echo "
    Ispis matrice u tabeli"; echo ''; for ($row = 1; $row < $ukupnoRedova; $row++) { echo ""; 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 ""; } echo ""; } echo '
    ".$csv[$row][$col]."
    '; ini_set('auto_detect_line_endings',FALSE); ?>