Created
December 12, 2009 12:30
-
-
Save dwiash/254861 to your computer and use it in GitHub Desktop.
upload+proses file CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$temp_file = $_FILES["berkas"]["tmp_name"]; | |
if($_FILES["berkas"]["error"] == 0){ | |
$handle = @fopen($temp_file, "r"); | |
if ($handle) { | |
$arr = array(); // ini variable Array yang dipake buat nyimpen data dari CSV yang diupload | |
while (!feof($handle)) { | |
$buffer = fgets($handle); | |
if(trim($buffer) != ""){ | |
$arr_buffer = array(); | |
$arr_buffer = split(",", $buffer); | |
if(count($arr_buffer)){ | |
$arr[] = $arr_buffer; | |
} | |
} | |
} | |
fclose($handle); | |
// Data dari CSV tadi yang diupload sekarang masuk ke array $arr | |
// tinggal akses aja tuh si $arr | |
// ini buat ngebuktiin kalo data dari CSV udh masuk ke $arr | |
print("<pre>"); | |
print_r($arr); | |
print("</pre>"); | |
} | |
}else{ | |
print "gagal upload, terdapat kesalahan"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="process.php" method="post" enctype="multipart/form-data" > | |
<input type="file" name="berkas" /> | |
<input type="submit" name="submit" value="kirim" /> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment