initial checkin from subversion
This commit is contained in:
324
index.php~
Normal file
324
index.php~
Normal file
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
$FP="files/".$_SERVER['PHP_AUTH_USER']."/";
|
||||
system ("mkdir -p '" . $FP . "'");
|
||||
|
||||
define('CHUNK_SIZE', 1024*1024); // Size (in bytes) of tiles chunk
|
||||
|
||||
// Read a file and display its content chunk by chunk
|
||||
function readfile_chunked($filename, $retbytes = TRUE) {
|
||||
$buffer = '';
|
||||
$cnt =0;
|
||||
// $handle = fopen($filename, 'rb');
|
||||
$handle = fopen($filename, 'rb');
|
||||
if ($handle === false) {
|
||||
return false;
|
||||
}
|
||||
while (!feof($handle)) {
|
||||
$buffer = fread($handle, CHUNK_SIZE);
|
||||
echo $buffer;
|
||||
ob_flush();
|
||||
flush();
|
||||
if ($retbytes) {
|
||||
$cnt += strlen($buffer);
|
||||
}
|
||||
}
|
||||
$status = fclose($handle);
|
||||
if ($retbytes && $status) {
|
||||
return $cnt; // return num. bytes delivered like readfile() does.
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
if (isset($_GET['dlFile'])){
|
||||
# doesn't work -- always gets killed (out of memory?)
|
||||
header('Content-disposition: attachment; filename='. $_GET["dlFile"]);
|
||||
header('Content-type: application/octet-stream');
|
||||
header('Content-Length: ' . filesize($FP . $_GET["dlFile"]));
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
readfile_chunked($FP . $_GET["dlFile"]);
|
||||
#readfile($FP . $_GET["dlFile"]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (isset($_GET['url'])) {
|
||||
system("cd '" . $FP . "';/usr/bin/wget --progress=dot '" . $_GET["url"] . "' 2>&1");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (isset($_GET['getFileList'])) {
|
||||
header('Content-type: application/json');
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
|
||||
system("cd '" . $FP . "';/bin/echo -n '{\"FileList\":['; /bin/ls | /usr/bin/sort | while read x; do if [ ! -f \".\${x}.md5\" ]; then /usr/bin/md5sum \"\${x}\" | /usr/bin/cut -c1-32 > \".\${x}.md5\"; fi; /bin/echo -n '{\"file\":{\"name\":\"'\${x}'\", \"md5\":\"'`/bin/cat \".\${x}.md5\"`'\", \"size\":\"'`/usr/bin/du -m \"\${x}\" | /usr/bin/cut -f1`'\"}},'; done; /bin/echo -n '{}]}'");
|
||||
exit (0);
|
||||
}
|
||||
|
||||
|
||||
if (isset($_SERVER['HTTP_X_FILENAME'])) {
|
||||
file_put_contents( $FP . $_SERVER['HTTP_X_FILENAME'], file_get_contents('php://input'));
|
||||
echo $_SERVER['HTTP_X_FILENAME'] . " uploaded";
|
||||
system("cd '" . $FP . "';/usr/bin/md5sum '" . $_SERVER['HTTP_X_FILENAME'] . "' | /usr/bin/cut -c1-32 > '." . $_SERVER['HTTP_X_FILENAME'] . ".md5'");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (isset($_GET['kill'])) {
|
||||
unlink($FP . $_GET['kill']);
|
||||
unlink($FP . "." . $_GET['kill'] . ".md5");
|
||||
exit(0);
|
||||
}
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
<title>NetSquat-Downloader
|
||||
<?php
|
||||
echo "[". $_SERVER['PHP_AUTH_USER'] . "]";
|
||||
?>
|
||||
</title>
|
||||
<style>
|
||||
#filedrag
|
||||
{
|
||||
display: none;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
padding: 1em 0;
|
||||
margin: 1em 0;
|
||||
color: #555;
|
||||
border: 2px dashed #555;
|
||||
border-radius: 7px;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
#filedrag.hover
|
||||
{
|
||||
color: #f00;
|
||||
border-color: #f00;
|
||||
border-style: solid;
|
||||
box-shadow: inset 0 3px 4px #888;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Enter URL</h1>
|
||||
<form action="" id='localFileUpload' method="POST" enctype="multipart/form-data">
|
||||
<fieldset><legend>Upload local file</legend>
|
||||
<input type="file" id='fileselect' name="files[]" multiple="multiple">
|
||||
<div id='filedrag'>or drop files here</div>
|
||||
</fieldset>
|
||||
<div id="UploadProgressBars">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<fieldset><legend>Download remote url</legend>
|
||||
<input name="url" id="url" size="100">
|
||||
<button id='btnDownload' onclick="downloader.downloadURL(document.getElementById('url').value)" >Download</button>
|
||||
<progress id='progress' style='display:none' value='0' max='100'></progress>
|
||||
</fieldset>
|
||||
<table id="fileList" border="0" style="font-family:monospace">
|
||||
<tbody>
|
||||
<tr><th>File</th><th>Size(MB)</th><th>MD5</th><th>KILL</th></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="messages">
|
||||
<p>Status Messages</p>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var downloader = (function () {
|
||||
"use strinct";
|
||||
|
||||
var allFiles= [];
|
||||
|
||||
// getElementById
|
||||
function $id(id) {
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
function delRequest(file){
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
//var fileData = JSON.parse(xmlhttp.responseText);
|
||||
fillFileList();
|
||||
}
|
||||
};
|
||||
xmlhttp.open("GET", "?kill=" + encodeURIComponent(file), true);
|
||||
xmlhttp.send();
|
||||
}
|
||||
|
||||
function fillFileList(){
|
||||
var xmlhttp = new XMLHttpRequest();
|
||||
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
|
||||
var fileData = JSON.parse(xmlhttp.responseText);
|
||||
|
||||
var tFL = document.getElementById("fileList");
|
||||
//alert(fileData);
|
||||
for(var i = tFL.rows.length-1; i > 0;i--) {
|
||||
tFL.deleteRow(i);
|
||||
}
|
||||
for(var i =0;i<fileData.FileList.length-1;i++) {
|
||||
var row = tFL.insertRow(tFL.rows.length);
|
||||
var cell1 = row.insertCell(0);
|
||||
cell1.innerHTML="<a href='<?php echo $FP ?>" + fileData.FileList[i].file.name +"'>" + fileData.FileList[i].file.name + "</a>" ;
|
||||
var cell2 = row.insertCell(1);
|
||||
cell2.innerHTML=fileData.FileList[i].file.size ;
|
||||
var cell3 = row.insertCell(2);
|
||||
cell3.innerHTML=fileData.FileList[i].file.md5 ;
|
||||
var cell4 = row.insertCell(3);
|
||||
cell4.innerHTML='<button onCLick="downloader.delRequest(\''+fileData.FileList[i].file.name+'\')">X</button>';
|
||||
}
|
||||
}
|
||||
};
|
||||
xmlhttp.open("GET", "?getFileList", true);
|
||||
xmlhttp.send();
|
||||
}
|
||||
|
||||
// initialize
|
||||
function Init() {
|
||||
var fileselect = $id("fileselect"),
|
||||
filedrag = $id("filedrag");
|
||||
|
||||
// file select
|
||||
fileselect.addEventListener("change", FileSelectHandler, false);
|
||||
|
||||
// file drop
|
||||
filedrag.addEventListener("dragover", FileDragHover, false);
|
||||
filedrag.addEventListener("dragleave", FileDragHover, false);
|
||||
filedrag.addEventListener("drop", FileSelectHandler, false);
|
||||
filedrag.style.display = "block";
|
||||
|
||||
fillFileList();
|
||||
}
|
||||
|
||||
// file drag hover
|
||||
function FileDragHover(e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
e.target.className = (e.type == "dragover" ? "hover" : "");
|
||||
}
|
||||
|
||||
|
||||
// file selection
|
||||
function FileSelectHandler(e) {
|
||||
|
||||
// cancel event and hover styling
|
||||
FileDragHover(e);
|
||||
|
||||
// fetch FileList object
|
||||
var files = e.target.files || e.dataTransfer.files;
|
||||
|
||||
// process all File objects
|
||||
for (var i = 0, f; f = files[i]; i++) {
|
||||
ParseFile(f);
|
||||
UploadFile(f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function ParseFile(file) {
|
||||
Output(
|
||||
"<p>File information: <strong>" + file.name +
|
||||
"</strong> type: <strong>" + file.type +
|
||||
"</strong> size: <strong>" + file.size +
|
||||
"</strong> bytes</p>"
|
||||
);
|
||||
}
|
||||
|
||||
// Download URL
|
||||
function downloadURL(url) {
|
||||
// create progress bar
|
||||
$id("url").readOnly = true;
|
||||
$id("btnDownload").style.display='none';
|
||||
$id("progress").value=0;
|
||||
$id("progress").style.display='';
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
$id("btnDownload").style.display='';
|
||||
$id("progress").style.display='none';
|
||||
$id("url").value = "";
|
||||
$id("url").readOnly = false;
|
||||
fillFileList();
|
||||
}
|
||||
}
|
||||
xhr.open("GET", "?url=" + encodeURIComponent(url), true);
|
||||
xhr.send();
|
||||
|
||||
var timer;
|
||||
timer = window.setInterval(function() {
|
||||
if (xhr.readyState == XMLHttpRequest.DONE) {
|
||||
window.clearTimeout(timer);
|
||||
Output('UrlDownload done <br />');
|
||||
}
|
||||
var tmpResponse=xhr.responseText;
|
||||
var lastIndex=tmpResponse.lastIndexOf("%");
|
||||
if (lastIndex>0) {
|
||||
var pctFinish=tmpResponse.substring(lastIndex-3,lastIndex);
|
||||
$id("progress").value = pctFinish;
|
||||
}
|
||||
// console.log(xhr.responseText);
|
||||
}, 300);
|
||||
}
|
||||
|
||||
// upload JPEG files
|
||||
function UploadFile(file) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
|
||||
var newPB=document.createElement("progress");
|
||||
newPB.setAttribute("id" ,"progressUL" + file.name);
|
||||
|
||||
var tn = document.createElement("div");
|
||||
tn.setAttribute("id", "ProgressFile" + file.name);
|
||||
tn.appendChild(document.createTextNode("FILE: " + file.name));
|
||||
|
||||
$id("UploadProgressBars").appendChild(tn);
|
||||
$id("UploadProgressBars").appendChild(newPB);
|
||||
|
||||
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
||||
Output(xhr.responseText);
|
||||
fillFileList();
|
||||
$id("progressUL" + file.name).parentNode.removeChild($id("progressUL" + file.name));
|
||||
$id("ProgressFile" + file.name).parentNode.removeChild($id("ProgressFile" + file.name));
|
||||
}
|
||||
}
|
||||
xhr.open("POST", $id("localFileUpload").action, true);
|
||||
xhr.setRequestHeader("X_FILENAME", file.name);
|
||||
xhr.send(file);
|
||||
// progress bar
|
||||
xhr.upload.addEventListener("progress", function(e) {
|
||||
$id("progressUL" + file.name).max = e.total;
|
||||
$id("progressUL" + file.name).value = e.loaded;
|
||||
}, false);
|
||||
}
|
||||
|
||||
// output information
|
||||
function Output(msg) {
|
||||
var m = $id("messages");
|
||||
m.innerHTML = msg + "<br>"+ m.innerHTML;
|
||||
}
|
||||
|
||||
// call initialization file
|
||||
if (window.File && window.FileList && window.FileReader) {
|
||||
Init();
|
||||
}
|
||||
|
||||
return {
|
||||
delRequest:delRequest,
|
||||
downloadURL:downloadURL
|
||||
};
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
<!--
|
||||
vim: sw=2 ts=2 si expandtab nowrap
|
||||
-->
|
||||
Reference in New Issue
Block a user