* Cleanup

This commit is contained in:
Momchil Bozhinov
2021-02-23 23:35:21 +02:00
parent b43aab5a10
commit 366ac6e865
3 changed files with 70 additions and 88 deletions

View File

@@ -58,13 +58,6 @@ class CBSD {
{
$cmd='cbsd media mode=register name=%s path=%s type=%s';
$res=self::run($cmd, array($file, $path.$file, $ext));
if($res['error']){
$arr['error']=true;
$arr['error_message']='File image not registered!';
} else {
$arr['error']=false;
}
echo json_encode($arr);
}
}

View File

@@ -1,6 +1,5 @@
<?php
if(isset($_GET['file']))
{
if(isset($_GET['file'])){
$file=$_GET['file'];
$filename=$file;
}else{
@@ -9,8 +8,9 @@ if(isset($_GET['file']))
}
$res=$clonos->userAutologin();
if(isset($res['id']) && $res['id']>0)
{
if(isset($res['id']) && $res['id']>0){
$file=$clonos->media_import.$file;
header('Content-disposition: attachment; filename='.$filename);
@@ -20,19 +20,19 @@ if(isset($res['id']) && $res['id']>0)
header('Content-Length: '.filesize($file));
header("Pragma: no-cache");
header("Expires: 0");
$chunkSize = 1024 * 1024;
$handle = fopen($file, 'rb');
while (!feof($handle))
{
$handle = fopen($file, 'rb');
while (!feof($handle))
{
$buffer = fread($handle, $chunkSize);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);
exit;
}
fclose($handle);
exit;
}
header('HTTP/1.1 401 Unauthorized');

View File

@@ -4,101 +4,90 @@ header('Content-Type: application/json');
require_once("../php/cbsd.php");
$cmd='';
$status = '';
if($_SERVER['REQUEST_METHOD'] === 'POST')
{
//$ppath=realpath('').'/media/';
if($_SERVER['REQUEST_METHOD'] === 'POST'){
$path=realpath('').'/media/';
if(isset($_POST['uplace']))
{
if(isset($_POST['uplace'])){
$res=strpos($_POST['uplace'],'jailscontainers');
if($res!==false)
{
//$ppath='/media_import/';
if($res!==false){
$path=$clonos->media_import;
$cmd='import';
}
$res=strpos($_POST['uplace'],'imported');
if($res!==false)
{
if($res!==false){
$path=$clonos->media_import;
$cmd='import';
}
}
//$path=realpath('').$ppath;
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
$ext = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
$file = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_FILENAME));
$uid = uniqid();
$date = time();
$returnJson[]=array('filepath'=>$path);
//$filename=$path.$filename.'-'.$uid.".".$ext;
$file=$file.'.'.$ext;
$filename=$path.$file; //.'.'.$ext;
if (move_uploaded_file($_FILES['file']['tmp_name'], $filename))
{
// https://www.php.net/manual/en/features.file-upload.php
// Undefined | Multiple Files | $_FILES Corruption Attack
// If this request falls under any of them, treat it invalid.
if (
!isset($_FILES['file']['error']) ||
is_array($_FILES['file']['error'])
) {
echo json_encode(array('status' => 'Upload Fail: An error occurred!';));
exit;
}
if(is_uploaded_file($_FILES['file']['tmp_name'])){
$basename = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_BASENAME));
if (move_uploaded_file($_FILES['file']['tmp_name'], $path.$basename)){
$status = 'ok'; //'Successfully uploaded!';
if($cmd=='import')
{
$res=CBSD::run('task owner=%s mode=new /usr/local/bin/cbsd jimport jname=%s' inter=0', [$clonos->getUserName(), $filename]);
if($cmd=='import'){
$res=CBSD::run('task owner=%s mode=new /usr/local/bin/cbsd jimport jname=%s inter=0', [$clonos->getUserName(), $path.$basename]);
}
}else{
} else {
$status = 'Upload Fail: Unknown error occurred!';
}
}
//echo '<pre>';print_r($_POST);
}
if($status!='ok') {echo json_encode(array('status' => $status));exit;}
return;
if($status!='ok'){
echo json_encode(array('status' => $status));
exit;
}
return; # TODO ?!
$valid_exts = array('image/jpeg', 'image/jpg', 'image/png', 'image/gif'); // valid extensions
$max_size = 30000 * 1024; // max file size in bytes
$json = array();
if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
{
for($i=0;$i<count($_FILES['file']['tmp_name']);$i++)
{
$path="/media/";
if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){
for($i=0;$i<count($_FILES['file']['tmp_name']);$i++){
$path="/media/";
if(is_uploaded_file($_FILES['file']['tmp_name'][$i]) )
{
// get uploaded file extension
$ext = strtolower(pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION));
// looking for format and size validity
if (in_array($ext, $valid_exts) AND $_FILES['file']['size'][$i] < $max_size)
{
// unique file path
$uid = uniqid();
$date = date('Y-m-d-H-i-s');
$path = $path ."image_" .$date. '_' . $uid . "." .$ext;
if(is_uploaded_file($_FILES['file']['tmp_name'][$i]) ){
// get uploaded file extension
$ext = strtolower(pathinfo($_FILES['file']['name'][$i], PATHINFO_EXTENSION));
// looking for format and size validity
if (in_array($ext, $valid_exts) AND $_FILES['file']['size'][$i] < $max_size){
// unique file path
$uid = uniqid();
$date = date('Y-m-d-H-i-s');
$path = $path ."image_" .$date. '_' . $uid . "." .$ext;
$returnJson[]= array("filepath"=>$path);
$filename = "image_" . $date . "_" .$uid . "." . $ext;
//$this->createthumb($i,$filename);
$filename = "image_" . $date . "_" .$uid . "." . $ext;
//$this->createthumb($i,$filename);
// move uploaded file from temp to uploads directory
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $path))
{
$status = 'ok'; //'Successfully uploaded!';
//perform sql updates here
}else{
$status = 'Upload Fail: Unknown error occurred!';
}
}else{
$status = 'Upload Fail: Unsupported file format or It is too large to upload!';
// move uploaded file from temp to uploads directory
if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $path)){
$status = 'ok'; //'Successfully uploaded!';
//perform sql updates here
} else {
$status = 'Upload Fail: Unknown error occurred!';
}
}else{
$status = 'Upload Fail: File not uploaded!';
} else {
$status = 'Upload Fail: Unsupported file format or It is too large to upload!';
}
} else {
$status = 'Upload Fail: File not uploaded!';
}
}else{
$status = 'Bad request!';
}
} else {
$status = 'Bad request!';
}
echo json_encode(array('status' => $status));
//echo json_encode($json);
echo json_encode(array('status' => $status));