Support name file
This commit is contained in:
parent
8a850aeaa6
commit
72870aa8a0
40
index.php
40
index.php
@ -32,6 +32,10 @@
|
|||||||
mkdir(_DATA_DIR . "/" . $rnd_data);
|
mkdir(_DATA_DIR . "/" . $rnd_data);
|
||||||
$info_json = new stdClass();
|
$info_json = new stdClass();
|
||||||
$info_json->expire = time() + (7 * 24 * 60 * 60);
|
$info_json->expire = time() + (7 * 24 * 60 * 60);
|
||||||
|
if ($_GET['name'])
|
||||||
|
{
|
||||||
|
$info_json->name = $_GET['name'];
|
||||||
|
}
|
||||||
file_put_contents(_DATA_DIR . "/" . $rnd_data . "/info.json", json_encode($info_json));
|
file_put_contents(_DATA_DIR . "/" . $rnd_data . "/info.json", json_encode($info_json));
|
||||||
|
|
||||||
$putdata = fopen("php://input", "r");
|
$putdata = fopen("php://input", "r");
|
||||||
@ -46,7 +50,7 @@
|
|||||||
|
|
||||||
if ($filesize < _SIZE_LIMIT )
|
if ($filesize < _SIZE_LIMIT )
|
||||||
{
|
{
|
||||||
print(_HTTP_PROTO . '://' . _HTTP_DOMAIN . _HTTP_PATH . 'data/' . $rnd_data . '/file');
|
print(_HTTP_PROTO . '://' . _HTTP_DOMAIN . _HTTP_PATH . 'index.php?id=' . $rnd_data );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -60,13 +64,41 @@
|
|||||||
// Informations for user
|
// Informations for user
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'GET')
|
if ($_SERVER['REQUEST_METHOD'] === 'GET')
|
||||||
{
|
{
|
||||||
if (stristr($_SERVER["HTTP_USER_AGENT"], 'curl') or stristr($_SERVER["HTTP_USER_AGENT"], 'Wget'))
|
if ($_GET['id'])
|
||||||
{
|
{
|
||||||
print("To upload file, use # curl --upload-file my_file " . _HTTP_PROTO . '://' . _HTTP_DOMAIN . _HTTP_PATH . "index.php\n");
|
if (is_dir(_DATA_DIR . "/" . $_GET['id']))
|
||||||
|
{
|
||||||
|
$data_conf = json_decode(file_get_contents(_DATA_DIR . "/" . $_GET['id'] . "/info.json"),true);
|
||||||
|
if ($data_conf['name'])
|
||||||
|
{
|
||||||
|
$filename = $data_conf['name'];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$filename = "file";
|
||||||
|
}
|
||||||
|
$file = _DATA_DIR . "/" . $_GET['id'] . "/file" ;
|
||||||
|
header('Content-Type: application/octet-stream');
|
||||||
|
header("Content-Transfer-Encoding: Binary");
|
||||||
|
header('Content-Length: ' . filesize($file));
|
||||||
|
header("Content-disposition: attachment; filename=\"" . $filename . "\"");
|
||||||
|
readfile($file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
http_response_code(404);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
include("front.php" );
|
if (stristr($_SERVER["HTTP_USER_AGENT"], 'curl') or stristr($_SERVER["HTTP_USER_AGENT"], 'Wget'))
|
||||||
|
{
|
||||||
|
print("To upload file, use # curl --upload-file my_file " . _HTTP_PROTO . '://' . _HTTP_DOMAIN . _HTTP_PATH . "index.php\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
include("front.php" );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
script.js
10
script.js
@ -3,7 +3,8 @@ function file_dropped(e)
|
|||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
fileobj = e.dataTransfer.files[0];
|
fileobj = e.dataTransfer.files[0];
|
||||||
upload_file(fileobj);
|
filename = e.dataTransfer.files[0].name;
|
||||||
|
upload_file(fileobj,filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
function file_explorer() {
|
function file_explorer() {
|
||||||
@ -11,7 +12,8 @@ function file_explorer() {
|
|||||||
document.getElementById('uploadfile').onchange = function()
|
document.getElementById('uploadfile').onchange = function()
|
||||||
{
|
{
|
||||||
fileobj = document.getElementById('uploadfile').files[0];
|
fileobj = document.getElementById('uploadfile').files[0];
|
||||||
upload_file(fileobj);
|
filename = document.getElementById('uploadfile').files[0].name;
|
||||||
|
upload_file(fileobj,filename);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,12 +28,12 @@ function copytoclipboard()
|
|||||||
document.execCommand("Copy");
|
document.execCommand("Copy");
|
||||||
}
|
}
|
||||||
|
|
||||||
function upload_file(file_obj)
|
function upload_file(file_obj,file_name)
|
||||||
{
|
{
|
||||||
var divresponse = document.getElementById('divresponse');
|
var divresponse = document.getElementById('divresponse');
|
||||||
divresponse.innerHTML = "Uploading file..." ;
|
divresponse.innerHTML = "Uploading file..." ;
|
||||||
const request = async () => {
|
const request = async () => {
|
||||||
var response = await fetch('/index.php', {
|
var response = await fetch('/index.php?name=' + file_name, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: file_obj
|
body: file_obj
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user