function execute() { $photo_id = Request::get('photo_id'); $photo_type = Request::get('photo_type'); $model = new connectionUserPhotoModel(); if (!in_array($photo_type, array_keys($model->dir))) { $this->notFound(); } $photo = $model->getPhotoByID($photo_id); if (!$photo) { $this->notFound(); } return ConnectionHelper::getPhotoDir($photo['user_id']) . $model->dir[$photo_type] . '/' . $photo['file']; }
function execute() { $files = Request::files('photo'); if (!$files || sizeof($files) == 0) { return; } $user = ConnectionHelper::userLogin(); $uploadDir = ConnectionHelper::getPhotoDir($user['id']); $model = new connectionUserPhotoModel(); File::mkdir($uploadDir); foreach ($files as $file) { $file_info = pathinfo($file['name']); if (!in_array(strtolower($file_info['extension']), array('png', 'jpeg', 'jpg', 'gif'))) { continue; } $file_name = uniqid() . strtotime('now') . md5(rand()) . '.' . $file_info['extension']; File::upload($file, $uploadDir, $file_name); $model->addPhoto($user['id'], $file_name); } }
function getImageSize($id, $user_id, $size) { $photo = $this->getPhotoByID($id); $file = $photo; if (empty($file)) { return false; } $dir = ConnectionHelper::getPhotoDir($user_id) . 'original/'; $temp = TEMP_DIR . DS . 'avatars'; File::mkdir($temp); if (!$size) { return $dir . $file['file']; } if ($size) { $tempfile = $temp . DS . 'user-' . $user_id . '-' . $id . '-' . $size . '-' . $file['file']; if (file_exists($tempfile)) { return $tempfile; } $resize = new Resize($dir . $file['file']); $sizes = getimagesize($dir . $file['file']); $index = 1; if ($sizes[0] >= $sizes[1]) { $index = $sizes[1] / $size; } else { $index = $sizes[0] / $size; } if ($index < 1) { $index = 1; } $resize->resizeImage(ceil($sizes[0] / $index), ceil($sizes[1] / $index)); $resize->saveImage($tempfile); return $tempfile; } }