Skip to content

Instantly share code, notes, and snippets.

@Aziz-Rahman
Created December 4, 2015 02:18
Show Gist options
  • Save Aziz-Rahman/6171a338118861745b1f to your computer and use it in GitHub Desktop.
Save Aziz-Rahman/6171a338118861745b1f to your computer and use it in GitHub Desktop.
Multiple upload
<?php
if(isset( $_FILES["gambar"] ) ){
//Ulang di setiap file
for( $i=0; $i<count($_FILES["gambar"]["name"] ); $i++ ) {
//Deteksi temporari path $tmpFilePath = $_FILES["gambar"]['tmp_name'][$i];
//Cek apakah file yang diupload lebih dari satu
if ( $tmpFilePath != "" ) {
//Set path/folder baru untuk tempat upload
$newFilePath = "files/" . $_FILES["gambar"]["name"][$i];
//Upload file dari temporari path ke folder baru
$upload = move_uploaded_file( $tmpFilePath, $newFilePath );
if ( $upload ) {
echo "sukses upload";
} else {
echo "gagal upload";
}
}
}
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="gambar[]" multiple> <input type="submit">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment