Add human bytes conversion with maximum size (#7)
This commit is contained in:
parent
907d92639f
commit
2ec44d4a50
@ -3,6 +3,6 @@
|
||||
define('_HTTP_PROTO','http');
|
||||
define('_HTTP_DOMAIN','localhost:8080'); // domain/IP with port if needed
|
||||
define('_HTTP_PATH','/');
|
||||
define('_SIZE_LIMIT','2000000'); // in bytes
|
||||
define('_SIZE_LIMIT','2097152'); // in bytes
|
||||
define('_PRETTY_URL', false); // Based on htaccess
|
||||
?>
|
@ -24,13 +24,15 @@
|
||||
<div id=dragzone class=dragndrop ondrop="file_dropped(event);" ondragover="return false" ondragenter="change_color_ondrag('ondragenter');" ondragleave="change_color_ondrag('ondragleave');" >
|
||||
Drag and Drop your file or <input class="button" type="button" value="Select File" onclick="file_explorer();">
|
||||
<input type="file" id="uploadfile" hidden>
|
||||
<br>
|
||||
<small>(Maximum <?php print(formatBytes(_SIZE_LIMIT)); ?>)</small>
|
||||
<br><br><br><br>
|
||||
<div id=divresponse></div><button class="button" id=copytoclipboard style="visibility: hidden;" onclick="copytoclipboard();">Copy to clipboard</button>
|
||||
</div>
|
||||
<div class=infobox>
|
||||
This tool is usable with <b>curl</b> or <b>wget</b>.<br><br>
|
||||
|
||||
To upload file: <br>
|
||||
To upload file (max <?php print(formatBytes(_SIZE_LIMIT)); ?>): <br>
|
||||
<li> curl --upload-file ./my_file <?php print($uploadurl);?><br>
|
||||
<li> wget -q --body-file='./my_file' --method=PUT -O - <?php print($uploadurl);?><br><br>
|
||||
|
||||
|
15
index.php
15
index.php
@ -11,6 +11,13 @@
|
||||
return rmdir($dir);
|
||||
}
|
||||
|
||||
function formatBytes($size, $precision = 2) {
|
||||
$base = log($size, 1024);
|
||||
$suffixes = array('', 'KB', 'MB', 'GB', 'TB');
|
||||
|
||||
return round(pow(1024, $base - floor($base)), $precision) . $suffixes[floor($base)];
|
||||
}
|
||||
|
||||
// Check if file have to be deleted
|
||||
$data_dir = array_diff(scandir(_DATA_DIR), array('..', '.', '.gitkeep'));
|
||||
foreach ($data_dir as $data_dir_content)
|
||||
@ -65,12 +72,12 @@
|
||||
|
||||
if ($filesize < _SIZE_LIMIT )
|
||||
{
|
||||
print($downloadurl . $rnd_data );
|
||||
print($downloadurl . $rnd_data . "\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
delTree(_DATA_DIR . "/" . $rnd_data);
|
||||
print("File size exceeded (Max " . _SIZE_LIMIT . " bytes)");
|
||||
print("File size exceeded (Max " . formatBytes(_SIZE_LIMIT) . " bytes)");
|
||||
}
|
||||
|
||||
|
||||
@ -108,7 +115,7 @@
|
||||
{
|
||||
if (stristr($_SERVER["HTTP_USER_AGENT"], 'curl') or stristr($_SERVER["HTTP_USER_AGENT"], 'Wget'))
|
||||
{
|
||||
print("To upload file:\n");
|
||||
print("To upload file (max " . formatBytes(_SIZE_LIMIT) . "):\n");
|
||||
print("* curl --upload-file my_file " . $uploadurl . "\n");
|
||||
print("* wget -q --body-file my_file --method=PUT -O - " . $uploadurl . "\n");
|
||||
print("\n");
|
||||
@ -123,4 +130,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
Loading…
Reference in New Issue
Block a user