2019-04-28 15:27:55 +02:00
|
|
|
<?php
|
|
|
|
// Load configuration
|
|
|
|
include 'conf/config.php';
|
|
|
|
|
|
|
|
// Check if file have to be deleted
|
|
|
|
$data_dir = array_diff(scandir(_DATA_DIR), array('..', '.', '.gitkeep'));
|
|
|
|
foreach ($data_dir as $data_dir_content)
|
|
|
|
{
|
|
|
|
$data_conf = json_decode(file_get_contents(_DATA_DIR . "/" . $data_dir_content . "/info.json"),true);
|
2019-04-28 16:43:14 +02:00
|
|
|
if ($data_conf['expire'] < time())
|
2019-04-28 15:27:55 +02:00
|
|
|
{
|
|
|
|
$i = new DirectoryIterator(_DATA_DIR . "/" . $data_dir_content);
|
|
|
|
foreach($i as $f) {
|
|
|
|
if($f->isFile())
|
|
|
|
{
|
|
|
|
unlink($f->getRealPath());
|
|
|
|
} else if(!$f->isDot() && $f->isDir()) {
|
|
|
|
rrmdir($f->getRealPath());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rmdir(_DATA_DIR . "/" . $data_dir_content );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Upload File
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'PUT')
|
|
|
|
{
|
|
|
|
$rnd_data = mt_rand(10000,99999);
|
|
|
|
mkdir(_DATA_DIR . "/" . $rnd_data);
|
2019-04-28 16:49:07 +02:00
|
|
|
$info_json = array();
|
2019-04-28 15:27:55 +02:00
|
|
|
$info_json->expire = time() + (7 * 24 * 60 * 60);
|
|
|
|
file_put_contents(_DATA_DIR . "/" . $rnd_data . "/info.json", json_encode($info_json));
|
|
|
|
|
|
|
|
$putdata = fopen("php://input", "r");
|
|
|
|
$fp = fopen(_DATA_DIR . "/" . $rnd_data . "/file", "w");
|
|
|
|
while ($data = fread($putdata, 1024))
|
|
|
|
{
|
|
|
|
fwrite($fp, $data);
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
fclose($putdata);
|
|
|
|
print(_HTTP_PROTO . '://' . _HTTP_DOMAIN . _HTTP_PATH . 'data/' . $rnd_data . '/file');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Informations for user
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'GET')
|
|
|
|
{
|
|
|
|
if (stristr($_SERVER["HTTP_USER_AGENT"], 'curl'))
|
|
|
|
{
|
|
|
|
print("To upload file, use # curl --upload-file my_file " . _HTTP_PROTO . '://' . _HTTP_DOMAIN . _HTTP_PATH . "index.php\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
include("front.php" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|