86 lines
3.1 KiB
PHP
86 lines
3.1 KiB
PHP
|
|
<?
|
||
|
|
|
||
|
|
namespace controller\common\video;
|
||
|
|
|
||
|
|
use common\Video;
|
||
|
|
use ms\MS;
|
||
|
|
use ms\ms\structure\msControllerTable;
|
||
|
|
|
||
|
|
class Api extends msControllerTable {
|
||
|
|
|
||
|
|
static $class = 'common\Video';
|
||
|
|
|
||
|
|
static function uploadProfile(){
|
||
|
|
$ALLOW_IMAGE_UPLOAD = MS::ALLOW_VIDEO_UPLOAD;
|
||
|
|
$res = new \stdClass();
|
||
|
|
$res->e = 0;
|
||
|
|
$res->link = 0;
|
||
|
|
if(IF_PROFILE){
|
||
|
|
if ($res->e == 0) {
|
||
|
|
if (count($_FILES)) {
|
||
|
|
$c = 0;
|
||
|
|
foreach ($_FILES as $f) {
|
||
|
|
$uplohost = \Core::$FOLDER;
|
||
|
|
$uploaddir = '/upload/video/acc'.\Site::$owner_id.'/profile'.PID.'/';
|
||
|
|
|
||
|
|
$part = explode(".", $f['name']);
|
||
|
|
$ext = strtolower($part[count($part) - 1]);
|
||
|
|
|
||
|
|
$name = time() . '_' . ($c++);
|
||
|
|
$fname = $name . "." . $ext;
|
||
|
|
|
||
|
|
if (!in_array($ext,$ALLOW_IMAGE_UPLOAD)){
|
||
|
|
$res->e = 1;
|
||
|
|
$res->m = 'Разрешённые форматы файлов для загрузки: <b>.'.implode('</b>, <b>.',$ALLOW_IMAGE_UPLOAD).'</b>';
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
$file = $uplohost . $uploaddir . $fname;
|
||
|
|
|
||
|
|
if (!file_exists($uplohost . $uploaddir)) {
|
||
|
|
mkdir($uplohost . $uploaddir, 0755, true);
|
||
|
|
}
|
||
|
|
if (move_uploaded_file($f['tmp_name'], $file)) {
|
||
|
|
chmod($file,0777);
|
||
|
|
|
||
|
|
$fx = fopen($file,"r");
|
||
|
|
$s = "";
|
||
|
|
while(!feof($fx)) {
|
||
|
|
$s .= fgets($fx);
|
||
|
|
}
|
||
|
|
$s = substr($s,strpos($s,",")+1);
|
||
|
|
fclose($fx);
|
||
|
|
$w = fopen($file,"w");
|
||
|
|
fwrite($w,base64_decode($s));
|
||
|
|
fclose($w);
|
||
|
|
|
||
|
|
$tobase = $uploaddir . $fname;
|
||
|
|
$r = Video::insert([
|
||
|
|
Video::$URL =>$tobase,
|
||
|
|
Video::$PROFILE =>intval(PID),
|
||
|
|
]);
|
||
|
|
$res->id = $r->id;
|
||
|
|
$res->link = $tobase;
|
||
|
|
|
||
|
|
|
||
|
|
$res->id = $r->id;
|
||
|
|
$res->link = $tobase;
|
||
|
|
$res->src = \Site::sectionUrl(substr($tobase,1),true);
|
||
|
|
$res->location = $tobase;
|
||
|
|
//$res->link = $U->imageResize($tobase,1920);
|
||
|
|
} else {
|
||
|
|
$res->e = 1;
|
||
|
|
$res->m = 'Произошла ошибка при загрузки видео';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$res->e = 1;
|
||
|
|
$res->m = 'Прикрепите, пожалуйста, файл.';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
echo je($res);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|