first commit

This commit is contained in:
Lionel 2020-11-08 15:07:01 +01:00
commit 4ee46c5f35
13 changed files with 817 additions and 0 deletions

5
apacheConf/apache2.conf Normal file
View File

@ -0,0 +1,5 @@
#Add these lines to apache2.conf
<Directory /var/www/html/uploads/>
Options -Indexes -FollowSymLinks
php_flag engine off
</Directory>

24
apacheConf/php.ini Normal file
View File

@ -0,0 +1,24 @@
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; http://php.net/post-max-size
;post_max_size = 8M
post_max_size = 5G
; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =
; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
;upload_max_filesize = 2M
upload_max_filesize = 5G
; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

22
delete.php Normal file
View File

@ -0,0 +1,22 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$root = $_SERVER["DOCUMENT_ROOT"];
$directory = "/uploads/";
if(isset($_GET["file"])) {
$file = $root.$directory.$_GET["file"];
if(file_exists($file))
unlink($file);
else {
header("HTTP/1.1 400 File not Found");
echo "File not Found";
exit();
}
}
//header('Refresh:0; url='.$_SERVER['HTTP_REFERER']);
?>

37
index.html Normal file
View File

@ -0,0 +1,37 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<link href="style/style.css" rel="stylesheet">
<link rel="stylesheet" href="style/imagepreview.min.css"/>
<link href="/fontawesome/css/all.css" rel="stylesheet" />
<title>Local Transfer</title>
</head>
<body>
<div class="transfer">
<div id="drop-area">
<form class="my-form">
<p>Upload multiple files with the file dialog or by dragging and dropping images onto the dashed region</p>
<input type="file" id="fileElem" multiple onchange="handleFiles(this.files)">
<label class="button" for="fileElem">Select some files</label>
</form>
<!--<div class="remaining">
<div class="progress" style="display: none;">
<div class="progress-bar"></div>
</div>
<div id="speed"></div>
</div>
<div id="uploadStatus"></div>-->
<div id="gallery"></div>
<div id="list"></div>
</div>
<div class="list"></div>
</div>
<div id="transProgress"></div>
<script src="js/jquery-3.5.1.min.js" type="text/javascript"></script>
<script src="js/imagepreview.min.js" type="text/javascript"></script>
<script src="js/script.js"></script>
</body>
</html>

1
js/imagepreview.min.js vendored Normal file
View File

@ -0,0 +1 @@
!function(a){"use strict";a.fn.anarchytip=function(b){var c=a.extend({xOffset:10,yOffset:30},b);return this.each(function(){var b=a(this);b.hover(function(b){this.t=this.title,this.title="";var d=""!=this.t?"<br/>"+this.t:"";a("body").append("<p id='preview'><img src='"+this.href+"' alt='Image preview' />"+d+"</p>"),a("#preview").css({top:b.pageY-c.xOffset+"px",left:b.pageX+c.yOffset+"px"}).fadeIn()},function(){this.title=this.t,a("#preview").remove()}),b.mousemove(function(b){a("#preview").css("top",b.pageY-c.xOffset+"px").css("left",b.pageX+c.yOffset+"px")})})}}(jQuery);

2
js/jquery-3.5.1.min.js vendored Normal file

File diff suppressed because one or more lines are too long

2
js/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

270
js/script.js Normal file
View File

@ -0,0 +1,270 @@
$(document).ready(function() {
listFile();
}); // document.ready
let dropArea = document.getElementById('drop-area');
let filesDone = 0;
let filesToDo = 0;
let progressBar = document.getElementById('progress-bar');
let lock = 0;
$(window).on('beforeunload', function () {
if(lock == 1) {
return false;
}
});
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, preventDefaults, false)
})
function preventDefaults (e) {
e.preventDefault()
e.stopPropagation()
};
['dragenter', 'dragover'].forEach(eventName => {
dropArea.addEventListener(eventName, highlight, false)
});
['dragleave', 'drop'].forEach(eventName => {
dropArea.addEventListener(eventName, unhighlight, false)
})
function highlight(e) {
dropArea.classList.add('highlight')
}
function unhighlight(e) {
dropArea.classList.remove('highlight')
}
dropArea.addEventListener('drop', handleDrop, false)
function handleDrop(e) {
let dt = e.dataTransfer
let files = dt.files
handleFiles(files)
}
function handleFiles(files) {
files = [...files]
files.forEach(uploadFile)
files.forEach(previewFile)
}
function uploadFile(file) {
let url = 'upload.php'
let formData = new FormData()
var title = file.name;
var startTime, endTime, fileSize, fileLoad;
formData.append('file', file)
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener("loadstart", function(e){
this.progressId = "progress_" + Math.floor((Math.random() * 100000));
this.name = title;
$("#transProgress").append('<div class="progress" id="' + this.progressId + '" ><i class="fa fa-upload"></i><span class="name"></span><progress value="0" max="100"></progress><span class="speed"></span></div>');
});
xhr.upload.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = ((evt.loaded / evt.total) * 100);
endTime = (new Date()).getTime();
fileSize = evt.total;
fileLoad = evt.loaded;
var speed = fileLoad / ((endTime - startTime)/1000) / 1024 / 1024; // get speed in MB/s
var speedMB = speed.toFixed(2) + ' MB/s ';
$('#' + this.progressId + ' > .name').text(this.name);
$('#' + this.progressId + ' > progress').prop('value', percentComplete);
$('#' + this.progressId + ' > .speed').text(speedMB + humanFileSize(fileLoad) + ' / ' + humanFileSize(fileSize));
}
}, false);
return xhr;
},
type: 'POST',
url: url,
data: formData,
contentType: false,
cache: false,
processData:false,
beforeSend: function(){
lock = 1;
$(".progress-bar").width('0%');
$(".progress").show();
startTime = (new Date()).getTime();
},
error: error,
success: function(data, statut){
lock = 0;
listFile();
}
});
}
function previewFile(file) {
if (isFileImage(file)) {
let reader = new FileReader()
reader.readAsDataURL(file)
reader.onloadend = function() {
let img = document.createElement('img')
img.src = reader.result
img.title = file.name + " " + humanFileSize(file.size);
document.getElementById('gallery').appendChild(img)
}
}
else {
let span = document.createElement('span')
span.innerHTML = file.name + " " + humanFileSize(file.size);
document.getElementById('list').appendChild(span)
document.getElementById('list').appendChild(document.createElement('br'))
}
}
function listFile() {
$.get({
url: 'list.php',
success: function(data, statut) {
$('.list').empty();
if (data.length > 0) {
$('.list').append('<i class="fa fa-times delall">&ensp;Delete all files</i><br>');
}
$.each(data, function(key, value) {
var encode = encodeURIComponent(value.name);
var title = value.name + ' ' + humanFileSize(value.size);
//$('.list').append('<a download name="' + value.name + '" class="download button ' + preview + '" href="' + value.href + '" title="' + title + '" ><i class="fa fa-' + value.type + ' type" aria-hidden="true"></i> ' + title + '</a>');
var a = $('<a />', {
class: 'download button',
href: value.href.replace(value.name, encodeURIComponent(value.name)),
name: value.name,
title: title,
html: '<i class="fa fa-' + value.type + ' type" aria-hidden="true"></i> ' + title
});
if (value.type == "file-image")
a.addClass('preview');
a.appendTo('.list');
$('.list').append('<a class="fa fa-times del" href="delete.php?file=' + encode + '"></a><br>');
});
$('.preview').anarchytip();
$('.del').click( function(event){
var href = $(this).attr("href");
$.get(href, listFile);
return false; // cancel the event (don't follow link)
});
$('.delall').click( function(event){
var i = 0;
var delNB = $('.del').length;
if(confirm("Are you sure you want to delete all files ?")) {
$('.del').each(function(index) {
var href = $(this).attr("href");
$.get(href, function() {
i++;
if(i == delNB) //if is the last get
listFile();
});
});
}
});
$('.download').click(downloadFile);
},
error: error,
dataType: 'json'
});
};
function downloadFile(event) {
var href = $(this).attr("href");
var title = $(this).attr('name');
var startTime, endTime, fileSize, fileLoad;
var progressId = "progress_" + Math.floor((Math.random() * 100000));
$.ajax({
xhr: function() {
var xhr = new window.XMLHttpRequest();
xhr.addEventListener("loadstart", function(e){
this.progressId = progressId;
this.name = title;
$("#transProgress").append('<div class="progress" id="' + this.progressId + '" ><i class="fa fa-download"></i><span class="name"></span><progress value="0" max="100"></progress><span class="speed"></span></div>');
});
xhr.addEventListener("progress", function(evt) {
if (evt.lengthComputable) {
var percentComplete = ((evt.loaded / evt.total) * 100);
endTime = (new Date()).getTime();
fileSize = evt.total;
fileLoad = evt.loaded;
var speed = fileLoad / ((endTime - startTime)/1000) / 1024 / 1024; // get speed in MB/s
var speedMB = speed.toFixed(2) + ' MB/s ';
$('#' + this.progressId + ' > .name').text(this.name);
$('#' + this.progressId + ' > progress').prop('value', percentComplete);
$('#' + this.progressId + ' > .speed').text(speedMB + humanFileSize(fileLoad) + ' / ' + humanFileSize(fileSize));
}
}, false);
return xhr;
},
url: href,
xhrFields:{
responseType: 'blob'
},
beforeSend: function(){
$(".progress-bar").width('0%');
$(".progress").show();
lock = 1;
startTime = (new Date()).getTime();
},
success: function(data){
lock = 0;
var blob = data;
var a = document.createElement("a");
var blobUrl = window.URL.createObjectURL(new Blob([blob], {type: blob.type}));
document.body.appendChild(a);
a.style = "display: none";
a.href = blobUrl;
console.log(blobUrl);
a.download = title ;
a.click();
a.remove();
},
error: error,
dataType: 'binary'
});
return false; // cancel the event (don't follow link)
};
function error(data, statut, error) {
lock = 0;
console.log(data);
//$('body').html(data['status'] + ' ' + error + '<br>' + data['responseText']);
};
function isFileImage(file) {
return file && file['type'].split('/')[0] === 'image';
}
function humanFileSize(bytes, si=false, dp=2) {
const thresh = si ? 1000 : 1024;
if (Math.abs(bytes) < thresh) {
return bytes + ' B';
}
const units = si
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
let u = -1;
const r = 10**dp;
do {
bytes /= thresh;
++u;
} while (Math.round(Math.abs(bytes) * r) / r >= thresh && u < units.length - 1);
return bytes.toFixed(dp) + ' ' + units[u];
};

264
list.php Normal file
View File

@ -0,0 +1,264 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$root = "/var/www/html";//$_SERVER["DOCUMENT_ROOT"];
$directory = "/uploads/";
$absolute_directory = "$root$directory";
$files = scandir($absolute_directory);
$files_array = array ();
foreach($files as $file) {
if (is_file($absolute_directory.$file)) {
$size = filesize($absolute_directory.$file);
$title = $file.' '.formatBytes($size);
$file_array = array(
'name' => $file,
'href' => $directory.$file,
'size' => $size,
'mime' => mime_type($absolute_directory.$file),
'type' => font_type($absolute_directory.$file)
);
array_push($files_array, $file_array);
}
}
echo json_encode($files_array);
function formatBytes($size, $precision = 2)
{
$base = log($size, 1024);
$suffixes = array('', 'KiB', 'MiB', 'GiB', 'TiB');
return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
}
function mime_type($file)
{
$types = array(
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'asc' => 'text/plain',
'atom' => 'application/atom+xml',
'atom' => 'application/atom+xml',
'au' => 'audio/basic',
'avi' => 'video/x-msvideo',
'bcpio' => 'application/x-bcpio',
'bin' => 'application/octet-stream',
'bmp' => 'image/bmp',
'cdf' => 'application/x-netcdf',
'cgm' => 'image/cgm',
'class' => 'application/octet-stream',
'cpio' => 'application/x-cpio',
'cpt' => 'application/mac-compactpro',
'csh' => 'application/x-csh',
'css' => 'text/css',
'csv' => 'text/csv',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'djv' => 'image/vnd.djvu',
'djvu' => 'image/vnd.djvu',
'dll' => 'application/octet-stream',
'dmg' => 'application/octet-stream',
'dms' => 'application/octet-stream',
'doc' => 'application/msword',
'dtd' => 'application/xml-dtd',
'dvi' => 'application/x-dvi',
'dxr' => 'application/x-director',
'eps' => 'application/postscript',
'etx' => 'text/x-setext',
'exe' => 'application/octet-stream',
'ez' => 'application/andrew-inset',
'gif' => 'image/gif',
'gram' => 'application/srgs',
'grxml' => 'application/srgs+xml',
'gtar' => 'application/x-gtar',
'hdf' => 'application/x-hdf',
'hqx' => 'application/mac-binhex40',
'htm' => 'text/html',
'html' => 'text/html',
'ice' => 'x-conference/x-cooltalk',
'ico' => 'image/x-icon',
'ics' => 'text/calendar',
'ief' => 'image/ief',
'ifb' => 'text/calendar',
'iges' => 'model/iges',
'igs' => 'model/iges',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'js' => 'application/x-javascript',
'json' => 'application/json',
'kar' => 'audio/midi',
'latex' => 'application/x-latex',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'm3u' => 'audio/x-mpegurl',
'man' => 'application/x-troff-man',
'mathml' => 'application/mathml+xml',
'me' => 'application/x-troff-me',
'mesh' => 'model/mesh',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mif' => 'application/vnd.mif',
'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'mpe' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpga' => 'audio/mpeg',
'ms' => 'application/x-troff-ms',
'msh' => 'model/mesh',
'mxu' => 'video/vnd.mpegurl',
'nc' => 'application/x-netcdf',
'oda' => 'application/oda',
'ogg' => 'application/ogg',
'pbm' => 'image/x-portable-bitmap',
'pdb' => 'chemical/x-pdb',
'pdf' => 'application/pdf',
'pgm' => 'image/x-portable-graymap',
'pgn' => 'application/x-chess-pgn',
'png' => 'image/png',
'pnm' => 'image/x-portable-anymap',
'ppm' => 'image/x-portable-pixmap',
'ppt' => 'application/vnd.ms-powerpoint',
'ps' => 'application/postscript',
'qt' => 'video/quicktime',
'ra' => 'audio/x-pn-realaudio',
'ram' => 'audio/x-pn-realaudio',
'ras' => 'image/x-cmu-raster',
'rdf' => 'application/rdf+xml',
'rgb' => 'image/x-rgb',
'rm' => 'application/vnd.rn-realmedia',
'roff' => 'application/x-troff',
'rss' => 'application/rss+xml',
'rtf' => 'text/rtf',
'rtx' => 'text/richtext',
'sgm' => 'text/sgml',
'sgml' => 'text/sgml',
'sh' => 'application/x-sh',
'shar' => 'application/x-shar',
'silo' => 'model/mesh',
'sit' => 'application/x-stuffit',
'skd' => 'application/x-koan',
'skm' => 'application/x-koan',
'skp' => 'application/x-koan',
'skt' => 'application/x-koan',
'smi' => 'application/smil',
'smil' => 'application/smil',
'snd' => 'audio/basic',
'so' => 'application/octet-stream',
'spl' => 'application/x-futuresplash',
'src' => 'application/x-wais-source',
'sv4cpio' => 'application/x-sv4cpio',
'sv4crc' => 'application/x-sv4crc',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml',
'swf' => 'application/x-shockwave-flash',
't' => 'application/x-troff',
'tar' => 'application/x-tar',
'tcl' => 'application/x-tcl',
'tex' => 'application/x-tex',
'texi' => 'application/x-texinfo',
'texinfo' => 'application/x-texinfo',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'tr' => 'application/x-troff',
'tsv' => 'text/tab-separated-values',
'txt' => 'text/plain',
'ustar' => 'application/x-ustar',
'vcd' => 'application/x-cdlink',
'vrml' => 'model/vrml',
'vxml' => 'application/voicexml+xml',
'wav' => 'audio/x-wav',
'wbmp' => 'image/vnd.wap.wbmp',
'wbxml' => 'application/vnd.wap.wbxml',
'wml' => 'text/vnd.wap.wml',
'wmlc' => 'application/vnd.wap.wmlc',
'wmls' => 'text/vnd.wap.wmlscript',
'wmlsc' => 'application/vnd.wap.wmlscriptc',
'wrl' => 'model/vrml',
'xbm' => 'image/x-xbitmap',
'xht' => 'application/xhtml+xml',
'xhtml' => 'application/xhtml+xml',
'xls' => 'application/vnd.ms-excel',
'xml' => 'application/xml',
'xpm' => 'image/x-xpixmap',
'xsl' => 'application/xml',
'xslt' => 'application/xslt+xml',
'xul' => 'application/vnd.mozilla.xul+xml',
'xwd' => 'image/x-xwindowdump',
'xyz' => 'chemical/x-xyz',
'zip' => 'application/zip'
);
$mime = mime_content_type($file);
$ext = pathinfo($file, PATHINFO_EXTENSION);
if($mime == "application/octet-stream" && array_key_exists($ext, $types))
return $types[$ext];
else
return $mime;
}
function font_type($file)
{
$mime = mime_type($file);
$type = explode('/', $mime);
$archive = ['x-tar', 'x-gzip', 'x-bzip', 'x-bzip2', 'zip', 'x-7z-compressed', 'x-rar-compressed', 'vnd.debian.binary-package', 'java-archive'];
$word = ['msword', 'vnd.openxmlformats-officedocument.wordprocessingml.document', 'vnd.oasis.opendocument.text'];
$excel = ['vnd.ms-excel', 'vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'vnd.oasis.opendocument.spreadsheet'];
$powerpoint = ['vnd.ms-powerpoint', 'vnd.openxmlformats-officedocument.presentationml.presentation', 'vnd.oasis.opendocument.presentation'];
$code = ['html', 'x-shellscript'];
switch ($type[0]) {
case "image":
return "file-image";
break;
case "audio":
return "file-audio";
break;
case "video":
return "file-video";
break;
case "application":
if(in_array($type[1], $archive))
return "file-archive";
if(in_array($type[1], $word))
return "file-word";
if(in_array($type[1], $excel))
return "file-excel";
if(in_array($type[1], $powerpoint))
return "file-powerpoint";
if($type[1] == "pdf")
return "file-pdf";
return "file";
case "text":
if(in_array($type[1], $code))
return "file-code";
return "file-alt";
default:
return "file";
}
}
?>

14
phpinfo.php Normal file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
PHP?
<?php
phpinfo();
?>
</body>
</html>

1
style/imagepreview.min.css vendored Normal file
View File

@ -0,0 +1 @@
body{margin:0;padding:40px;background:#fff;font:80% Arial,Helvetica,sans-serif;color:#555;line-height:180%}h1{font-size:180%;font-weight:400;color:#555}h2{clear:both;font-size:160%;font-weight:400;color:#555;margin:0;padding:.5em 0}a{text-decoration:none;color:#f30}p{clear:both;margin:0;padding:.5em 0}pre{display:block;font:100% "Courier New",Courier,monospace;padding:10px;border:1px solid #bae2f0;background:#e3f4f9;margin:.5em 0;overflow:auto;width:800px}img{border:none;max-width: 300px;}ul,li{margin:0;padding:0}li{list-style:none;float:left;display:inline;margin-right:10px}#preview{position:absolute;border:1px solid #ccc;background:#333;padding:5px;display:none;color:#fff}

123
style/style.css Normal file
View File

@ -0,0 +1,123 @@
body {
font-family: Roboto, sans-serif;
color: #0f3c4b;
background-color: #e5edf1;
padding: 5rem 1.25rem; /* 80 20 */
}
.type {
font-size: 22px;
vertical-align: middle;
}
.transfer {
display: flex;
}
.list {
width: 50%;
}
.del, .delall {
cursor: pointer;
}
.progress {
display: flex;
justify-content: flex-end;
width: 50%;
border: solid;
border-width: 2px;
border-radius: 10px;
margin: 10px auto;
padding: 10px 20px;
vertical-align: middle;
}
.progress > * {
display: inline-block;
white-space: nowrap;
margin: 0 5px;
vertical-align: middle;
font-size: 18px;
}
.progress > .name {
max-width: 40%;
white-space: nowrap;
overflow: hidden;
margin-right: auto;
}
.progress > .speed {
text-align: center;
white-space: nowrap;
width: 300px;
}
a.button {
background-color: #c8dadf;
cursor: pointer;
display: inline-block;
text-align: center;
//border: 2px solid;
border-radius: 5px;
font-weight: bold;
margin: 5px;
color: #10a2ff;
padding: 1em 1.5em;
text-decoration: none;
}
a.del {
color: black;
cursor: pointer;
display: inline-block;
text-decoration: none;
}
#drop-area {
border: 2px dashed #ccc;
border-radius: 20px;
width: 640px;
min-height: 480px;
font-family: sans-serif;
margin: auto;
margin-top: 0;
padding: 20px;
}
#drop-area.highlight {
border-color: purple;
}
p {
margin-top: 0;
}
.my-form {
margin-bottom: 10px;
}
#gallery {
margin-top: 10px;
}
#gallery img {
width: 150px;
margin-bottom: 10px;
margin-right: 10px;
vertical-align: middle;
}
.button {
display: inline-block;
padding: 10px;
background: #ccc;
cursor: pointer;
border-radius: 5px;
border: 1px solid #ccc;
}
.button:hover {
background: #ddd;
}
#fileElem {
display: none;
}

52
upload.php Normal file
View File

@ -0,0 +1,52 @@
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
$root = $_SERVER["DOCUMENT_ROOT"];
$target_dir = "$root/uploads/";
if(! isset($_FILES["file"])) {
header("HTTP/1.1 400 No file Upload");
//trigger_error("No file Upload",E_USER_ERROR);
exit();
}
$file = $_FILES["file"];
$name = basename($file["name"]);
if(! mb_check_encoding($name)) {
header("HTTP/1.1 400 Bad encode");
exit();
}
$size = basename($file["size"]);
$target_file = $target_dir.$name;
// Check if file already exists
if (file_exists($target_file)) {
header("HTTP/1.1 400 This file already exists");
echo "This file already exists.";
}
else {
if (move_uploaded_file($file["tmp_name"], $target_file)) {
echo "The File ".$name." of size ".formatBytes($size)." has been uploaded.";
} else {
header("HTTP/1.1 500");
echo "There was an error uploading your file.";
}
}
function formatBytes($size, $precision = 2)
{
$base = log($size, 1024);
$suffixes = array('', 'KiB', 'MiB', 'GiB', 'TiB');
return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)];
}
?>