Created
June 4, 2010 08:14
-
-
Save drewlesueur/425141 to your computer and use it in GitHub Desktop.
drag and drop files chrome
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
<!doctype html> | |
<html> | |
<head> | |
</head> | |
<body style="width:1000px; height: 1000px;"> | |
<h1>Drop</h1> | |
<script> | |
dropbox = document.body; | |
dropbox.addEventListener("dragenter", dragenter, false); | |
dropbox.addEventListener("dragover", dragover, false); | |
dropbox.addEventListener("drop", drop, false); | |
function dragenter(e) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
} | |
function dragover(e) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
} | |
function drop(e) { | |
e.stopPropagation(); | |
e.preventDefault(); | |
var dt = e.dataTransfer; | |
var files = dt.files; | |
handleFiles(files); | |
} | |
function handleFiles(files) { | |
for (var i = 0; i < files.length; i++) { | |
var file = files[i]; | |
console.log(file) | |
var xhr = new XMLHttpRequest; | |
xhr.open('post', 'http://vwtribe.com/unzip/', true); | |
xhr.onreadystatechange = function () { | |
console.log(this.readyState) | |
console.log(this.responseText); | |
} | |
xhr.onerror = function(e) {console.log(e)} | |
xhr.setRequestHeader('Content-Type', 'multipart/form-data'); | |
xhr.setRequestHeader('X-File-Name', file.fileName); | |
xhr.setRequestHeader('X-File-Size', file.fileSize); | |
xhr.send(file); // For some reason sending the actual F | |
} | |
} | |
</script> | |
</body> | |
</html> |
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
<? | |
$file = file_get_contents('php://input'); | |
file_put_contents('file.zip',$file); | |
$zip = new ZipArchive; | |
$res = $zip->open('file.zip'); | |
if ($res === TRUE) { | |
$zip->extractTo('/home/content/l/e/s/lesueur2/html/vwtribe.com/unzip/blah'); | |
$zip->close(); | |
echo file_get_contents('blah/vehicles.txt'); | |
} else { | |
echo 'failed'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment