Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
Created June 4, 2010 08:14
Show Gist options
  • Save drewlesueur/425141 to your computer and use it in GitHub Desktop.
Save drewlesueur/425141 to your computer and use it in GitHub Desktop.
drag and drop files chrome
<!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>
<?
$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