nativegallery-weryskok/app/Controllers/Api/Images/Upload.php

63 lines
2 KiB
PHP
Raw Normal View History

2024-07-05 07:26:39 +03:00
<?php
namespace App\Controllers\Api\Images;
use App\Services\{Auth, Router, GenerateRandomStr, DB, Json, EXIF};
use App\Services\Upload as UploadPhoto;
use \Aws\S3\MultipartUploader;
use \Aws\Exception\MultipartUploadException;
class Upload
{
static $continue;
static $photourl;
public static function create($postbody, $content, $exif)
{
2024-07-05 11:51:14 +03:00
DB::query('INSERT INTO photos VALUES (\'0\', :userid, :postbody, :photourl, :time, :timeup, :exif, 0, :place, :content)', array(':postbody' => $postbody, ':userid' => Auth::userid(), ':time' => mktime(0, 0, 0, $_POST['month'], $_POST['day'], $_POST['year']), ':content' => $content, ':photourl' => self::$photourl, ':exif' => $exif, ':place' => $_POST['place'], ':timeup'=>time()));
2024-07-05 07:26:39 +03:00
echo json_encode(
array(
2024-07-05 12:44:31 +03:00
'id' => DB::query('SELECT id FROM photos ORDER BY id DESC LIMIT 1')[0]['id'],
2024-07-05 07:26:39 +03:00
'errorcode' => 0,
'error' => 0
)
);
}
public function __construct()
{
2024-07-05 09:49:49 +03:00
if ($_FILES['image']['error'] != 4) {
$exif = new EXIF($_FILES['image']['tmp_name']);
2024-07-05 12:44:31 +03:00
$exif = $exif->getData();
2024-07-05 09:49:49 +03:00
$upload = new UploadPhoto($_FILES['image'], 'cdn/img');
2024-07-05 12:44:31 +03:00
if ($exif === null) {
$exif = Json::return(
array(
'type' => 'none',
)
);
}
2024-07-05 09:49:49 +03:00
if ($upload->getType() !== null) {
2024-07-05 07:26:39 +03:00
$content = Json::return(
array(
2024-07-05 09:49:49 +03:00
'type' => 'none',
'copyright' => $_POST['license'],
2024-07-05 12:58:12 +03:00
'comment' => $_POST['descr'],
2024-07-05 07:26:39 +03:00
)
);
2024-07-05 09:49:49 +03:00
self::$photourl = $upload->getSrc();
2024-07-05 12:44:31 +03:00
self::create($_POST['descr'], $content, $exif);
2024-07-05 07:26:39 +03:00
}
} else {
echo json_encode(
array(
'errorcode' => 'FILE_NOTSELECTED',
'error' => 1
)
);
}
}
}