From 1fc344a672c545033af340cdb4e104d903903ac7 Mon Sep 17 00:00:00 2001 From: Pavel Dmitriev Date: Tue, 8 Dec 2020 11:59:37 +0300 Subject: [PATCH] V1.0 --- .htaccess | 4 ++++ expunge.sh | 18 ++++++++++++++++++ index.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ test.php | 30 ++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) create mode 100644 .htaccess create mode 100644 expunge.sh create mode 100644 index.php create mode 100644 test.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..12ed129 --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ + + deny from all + + diff --git a/expunge.sh b/expunge.sh new file mode 100644 index 0000000..c1efc35 --- /dev/null +++ b/expunge.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +uploaddir='/var/www/html/files'; +timeout=30 + +list=`ls ${uploaddir}` + +for file in ${list} +do + prefix=`echo ${file} | awk -F '-' '{ print $1}'` + stamp=`date +%s` + delta=`expr ${stamp} - ${prefix}` + + if [[ "$delta" -gt "$timeout" ]] + then + rm -f "${uploaddir}/${file}" + fi +done diff --git a/index.php b/index.php new file mode 100644 index 0000000..585b266 --- /dev/null +++ b/index.php @@ -0,0 +1,52 @@ +"ERR","message"=>"Empty type"]); exit;} +if (array_search($type, $allowed_types) === false) {print json_encode(["status"=>"ERR","message"=>"Invalid type"]); exit;} +if (preg_match("/\.([^\.]*)$/", $_FILES['userfile']['name'], $r)) { + $name_tmp=preg_replace("![\.]!","-",time().".".uniqid(null,true)); + if (array_search(strtolower($r[1]), $allowed_ext) === false) {print json_encode(["status"=>"ERR","message"=>"Invalid src ext"]); exit;} + $src=$uploaddir."/".$name_tmp.".".$r[1]; + $dst=$uploaddir."/".$name_tmp.".".$type; + move_uploaded_file($_FILES['userfile']['tmp_name'], $src); + exec("/usr/bin/unoconv -n -f ".$type." -o '".$dst."' '".$src."'",$res,$code); + if ($code ==0) { + exec("rm -f ".$src); + } else { + exec("rm -f $src"); + exec("rm -f $dst"); + print json_encode(["status"=>"ERR","message"=>"Converter error. Code $code"]); + exit; + } +} else { + print json_encode(["status"=>"ERR","message"=>"Invalid src filename"]); + exit; +} + +if ($rtype=='html') { + print "$name_tmp.$type"; +} else { + print json_encode(["status"=>"OK","result"=>"/files/".$name_tmp.".".$type]); +} + +?> \ No newline at end of file diff --git a/test.php b/test.php new file mode 100644 index 0000000..f535d56 --- /dev/null +++ b/test.php @@ -0,0 +1,30 @@ + + + + + +
+ + + + + Отправить этот файл: + + + + + + +
+ + +