protected function uploadImage($url) { // Array ( [name] => Angus_cattle_18.jpg [type] => image/jpeg [tmp_name] => /tmp/php5lPQZT [error] => 0 [size] => 52162 ) $ary = []; $name = file::getFilename($url) . "." . file::getExtension($url); $ary['name'] = $name; $ary['abstract'] = file::getFilename($url); $ary['type'] = file::getMime($url); $ary['tmp_name'] = $url; $ary['error'] = 0; $ary['size'] = 0; $i = new \modules\image\uploadBlob(); $res = $i->insertFileDirect($ary, $this->reference, $this->parentId, $this->userId); if ($res) { $id = q::lastInsertId(); $row = $i->getSingleFileInfo($id); return $i->getFullWebPath($row); } else { log::error("Could not upload image: {$name}"); return false; } }
protected function saveMedia($url) { $type = file::getExtension($url); if ($type == 'mp4') { return $this->saveMp4($url); } else { return $this->saveImage($url); } }
protected function saveImage($url) { $id = direct::fragment(2, $url); $ext = file::getExtension($url); $title = md5(uniqid()) . ".{$ext}"; $i = new image(); $file = $i->getFile($id); if (empty($file)) { return ''; } $path = "/images/{$id}/{$title}"; $save_path = conf::getFullFilesPath($path); $web_path = conf::getWebFilesPath($path); $dir = dirname($path); file::mkdir($dir); file_put_contents($save_path, $file['file']); return $web_path; }
/** * Checks broken media * @param type $url * @return boolean */ protected function checkMedia($url) { $type = file::getExtension($url); if ($type == 'mp4' && self::$type == 'mp4') { return false; } return $url; }
/** * Get type of extension * @param type $url * @return type */ protected function getType($url) { $type = file::getExtension($url); return strtolower($type); }
/** * Checks broken media * @param type $url * @return boolean */ protected function isImage($url) { $type = file::getExtension($url); if ($type == 'mp4') { return false; } return true; }