Multiple php-Uploads mit eigenen Ordnern

Vorteil hier ist das für jeden gesamten Upload mehrer Bilder ein Ordner mit eindeutiger ID-Bemerkung
angelegt wird indem diese dann abgespeichert werden.

So könnte jeder im WLAN schnell via Handy, lappie oder sonst einem Medium Fotos auf einen lokalen Server hochladen.

DOWNLOADPACKAGE

<?php
if(isset($_REQUEST['AddFiles'])){
$targetFolder = 'upload'; //Path to the Uploads Folder 
$uniqid = uniqid($prefix);
$pathneu="";

	if (!empty($_FILES)) {
	if(isset($_REQUEST['vorname'])){

	
	$pathneu="upload/".$_REQUEST['vorname'].$uniqid;
	}else{
	$pathneu="upload/".$uniqid;
	}
mkdir($pathneu,0700);
		for($i=0;$i<count($_FILES['upload_file']['name']);$i++){
			$tempFile = $_FILES['upload_file']['tmp_name'][$i];
			$targetFile = rtrim($pathneu,'/') . '/' . $_FILES['upload_file']['name'][$i];
			$fileTypes = array('jpeg','jpg','png','gif','bmp'); // Allowed File extensions
			$fileParts = pathinfo($_FILES['upload_file']['name'][$i]);
			if(isset($fileParts['extension'])){
				if (in_array($fileParts['extension'],$fileTypes)) {
					move_uploaded_file($tempFile,$targetFile);
					echo '<div class="success">'.$_FILES['upload_file']['name'][$i].' was saved successfully inside '.$targetFolder.' Directory</div>';
				}else{
					echo '<div class="fail">'.$_FILES['upload_file']['name'][$i].' couldn\'t be saved because of invalid file type.</div>';
				}
			}else{
				echo '<div class="fail">'.$_FILES['upload_file']['name'][$i].' couldn\'t be saved because of invalid file type.</div>';
			}
		}
	}
}

?>
<html>
	<head>
	<script src="jquery-1.10.2.min.js" type="text/javascript"></script>
	<link rel="stylesheet" type="text/css" href="upload.css" media="screen" />
	<script>
        var selDiv = "";
	document.addEventListener("DOMContentLoaded", init, false);

	function init() {
		document.querySelector('#upload_file').addEventListener('change', handleFileSelect, false);
		selDiv = document.querySelector("#selectedFiles");
	}
		
	function handleFileSelect(e) {
		if(!e.target.files) return;
		var files = e.target.files;
		for(var i=0; i<files.length; i++) {
			var f = files[i];
			selDiv.innerHTML += "<div class='file_list'>"+f.name + "</div>";
		}
                $('#uploadimages').show();
	}
	
	$(document).ready(function(){
	    $("#uploadTrigger").click(function(){
		$("#upload_file").click();
            });	
	});

	</script>

	</head>
	<body>
	
		<div id="upload_pages">
		    
		   <form action="index2.php" enctype="multipart/form-data" method="POST">
		
			<input type="hidden" name="AddFiles" id="AddFiles" value="1">
		
			<input type="file" name="upload_file[]" class="hidden" id="upload_file" multiple />
		
			<hr>
			<strong id="form-text">Upload Images </strong>
			<div class="button" id="uploadTrigger">Select Images</div>
			<hr>
 <p>Dein Name:<br><input name="vorname" type="text" size="30" maxlength="30"></p>			
			<div id="selectedFiles"></div>    
			<input type="submit" value="Upload" id="uploadimages" />
		   </form>
		</div>
PHP-INI-Settings
upload_max_filesize = 1000M;
post_max_size = 1000M;
max_execution_time=600000
	</body>
</html>

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Denkhilfe *

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.