Created
June 23, 2018 23:30
-
-
Save jerry-maheswara-github/9527e53f9a4d3142bacd379b9afd932b to your computer and use it in GitHub Desktop.
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 | |
/* ------------------------------------------------------- | |
* Author: Jerry Maheswara | |
* Description: Upload Multiple File | |
* Silahkan dikembangkan lebih lanjut....!! | |
* Feel free to improve your code.... | |
* jangan sungkan-sungakan.... ini hanya sebagai dasar saja... | |
*/ | |
error_reporting(E_ALL); | |
$upload_dir= 'uploads'; // ini folder tempat file yg diupload | |
$num_uploads = 4; | |
$max_file_size = 5120000; | |
$upload_max = $max_file_size * 1024; | |
$msg = 'Pilih File untuk di upload'; | |
$messages = array(); | |
if(isset($_FILES['userfile']['tmp_name'])) | |
{ | |
for($i=0; $i < count($_FILES['userfile']['tmp_name']);$i++) | |
{ | |
if(!is_uploaded_file($_FILES['userfile']['tmp_name'][$i])) | |
{ | |
$messages[] = 'Upload Gagal'; | |
} | |
elseif($_FILES['userfile']['size'][$i] > $upload_max) | |
{ | |
$messages[] = "Ukuran file melebihi batas"; | |
} | |
elseif($_FILES['userfile']['size'][$i] > $max_file_size) | |
{ | |
$messages[] = "Ukuran file melebihi batas"; | |
} | |
else | |
{ | |
if(@copy($_FILES['userfile']['tmp_name'][$i],$upload_dir.'/'.$_FILES['userfile']['name'][$i])) | |
{ | |
$messages[] = $_FILES['userfile']['name'][$i].' uploaded'; | |
} | |
else | |
{ | |
$messages[] = 'Upload '.$_FILES['userfile']['name'][$i].' Gagal'; | |
} | |
} | |
} | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<title>Multiple File Upload</title> | |
</head> | |
<body> | |
<h3><?php echo $msg; ?></h3> | |
<p> | |
<?php | |
if(sizeof($messages) != 0) | |
{ | |
foreach($messages as $err) | |
{ | |
echo $err.'<br />'; | |
} | |
} | |
?> | |
</p> | |
<form enctype="multipart/form-data" method="post"> | |
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" /> | |
<?php | |
$num = 0; | |
while($num < $num_uploads) | |
{ | |
echo '<div><input name="userfile[]" type="file" /></div>'; | |
$num++; | |
} | |
?> | |
<input type="submit" value="Upload" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment