Created
March 31, 2015 07:37
-
-
Save Aziz-Rahman/edefa0c2159b5d22222d to your computer and use it in GitHub Desktop.
Menggunakan fungsi end(), uniqid, explode, & md 5
This file contains hidden or 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 | |
| // Connection | |
| $conn = mysqli_connect( "localhost", "root", "", "gallery" ) or die ( 'Error !'. mysqli_error( $conn ) ); | |
| $pure_image = $_FILES['image']['name']; // nama ft | |
| $files = end( explode( '.', $pure_image ) ); // memecah nm ft dan extention'nya, diambil kata dr titik paling belakang ( utk mengambil nm extention ) | |
| $file_name = $pure_image; // nama ft setelah dipecah/ dipisahkan dg extention'ny | |
| $file_ext = $files; // ext | |
| $hash_name = md5( uniqid( $file_name, true ) ); // mengenkrpsi nm file dan melakukan pangacakan nm file | |
| $img = $hash_name. ".$file_ext"; // menggabungkan nmfile + extention | |
| $path = 'images/'.$img; | |
| $sql = "INSERT INTO images( image ) VALUES( '$img' )"; | |
| $save_gallery = mysqli_query( $conn, $sql ); | |
| move_uploaded_file( $_FILES['image']['tmp_name'], $path ); | |
| if ( $save_gallery ){ | |
| echo "<script>alert( 'Data tersimpan !' ); document.location='./';</script>"; | |
| }else{ | |
| die ( "Gagal tersimpan !". mysqli_error( $conn ) ); | |
| } | |
| mysqli_close( $conn ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment