Created
September 12, 2013 02:53
-
-
Save ssddi456/6532598 to your computer and use it in GitHub Desktop.
upload folder demo
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 | |
$deploy_root=dirname(__FILE__); | |
function mkdirs($path, $mod = 0777) { | |
if (is_dir($path)) { | |
return chmod($path, $mod); | |
} else { | |
$old = umask(0); | |
if(mkdir($path, $mod, true) && is_dir($path)){ | |
umask($old); | |
return true; | |
} else { | |
umask($old); | |
} | |
} | |
return false; | |
} | |
foreach($_FILES['file']['name'] as $key => $val ){ | |
$relp = $_POST['fullpath'][$key]; | |
echo "<br>".$val.':'.$relp; | |
if( isset($_POST['to'] ) ){ | |
$tar = $deploy_root.'/'.$_POST['to'].'/'.$relp; | |
} | |
$dirname = dirname ( $tar ); | |
mkdirs($dirname); | |
if ( $val =='.'){ | |
} else { | |
echo '<br>$tar '.$tar; | |
if( file_exists($tar) ){ | |
if( isset($_POST['override'])){ | |
echo ' override'; | |
unlink($tar); | |
} else{ | |
echo ' exists skip'; | |
continue; | |
} | |
} | |
echo ' '.move_uploaded_file($_FILES['file']['tmp_name'][$key], $tar ); | |
} | |
} |
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="reciever.php" | |
method="post" | |
enctype="multipart/form-data"> | |
<table> | |
<tr><td> | |
files | |
</td><td> | |
<input name="file[]" id="upload" type="file" | |
webkitdirectory /> | |
<!-- mozdirectory --> | |
<!-- directory --> | |
</td></tr> | |
<tr><td> | |
deploy with path : | |
</td><td> | |
<input type="text" name="to"> | |
</td></tr> | |
<tr><td> | |
override | |
</td><td> | |
<input type="checkbox" name="override"> | |
</td></tr> | |
</table> | |
<input type="submit"> | |
<span id="relative_path"></span> | |
</form> | |
<script> | |
var $ = document.querySelector.bind(document); | |
var $file = $('#upload'); | |
var $relative_path = $('#relative_path'); | |
$file.addEventListener('change',function(e) { | |
var files = this.files; | |
var relp = ''; | |
var fileNameList = ''; | |
Array.prototype.forEach.call(files,function( file ){ | |
var withoutroot = file.webkitRelativePath.replace(/^([^\/]+)\//,'') | |
relp += '<input type="hidden" name="fullpath[]" value="'+ withoutroot +'"/>'; | |
fileNameList += '<br> ' + withoutroot ; | |
}); | |
$relative_path.innerHTML = relp + fileNameList; | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment