public function indexAction(Request $request, SessionInterface $session) { Util::checkUserIsLoggedInAndRedirect(); $loggedInUserId = $session->get('user/id'); $filenameData = apache_request_headers(); $filename = rawurldecode($filenameData['X_FILENAME']); $issueId = $request->request->get('issue_id'); if (!$session->has('added_attachments_in_screen')) { $session->set('added_attachments_in_screen', array()); } /* every attachment has its own dedicated sub-folder, so no editing on the upload filename will be done */ if ($filename) { $ext = substr($filename, strrpos($filename, '.') + 1); $filenameWithoutExtension = substr($filename, 0, strrpos($filename, '.')); $attachmentId = $this->getRepository(IssueAttachment::class)->add($issueId, Util::slugify($filenameWithoutExtension) . '.' . $ext, $loggedInUserId, Util::getServerCurrentDateTime()); if ($issueId == null) { $issueId = 'user_' . $loggedInUserId; } $uploadDirectory = Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId; /* subfolders */ $uploadDirSubfolder = $uploadDirectory . '/' . $attachmentId; if (!file_exists($uploadDirectory)) { mkdir($uploadDirectory); } if (!file_exists($uploadDirSubfolder)) { mkdir($uploadDirSubfolder); } $newFileName = $uploadDirSubfolder . '/' . Util::slugify($filenameWithoutExtension) . '.' . $ext; file_put_contents($newFileName, file_get_contents('php://input')); $size = filesize($newFileName); $temp = $session->get('added_attachments_in_screen'); $temp[] = $attachmentId; $session->set('added_attachments_in_screen', $temp); $this->getRepository(IssueAttachment::class)->updateSizeById($attachmentId, $size); if (Util::isImage(Util::getExtension($filename))) { $thumbUploaddirSubfolder = $uploadDirSubfolder . '/thumbs'; if (!file_exists($thumbUploaddirSubfolder)) { mkdir($thumbUploaddirSubfolder); } $newThumbnailName = $thumbUploaddirSubfolder . '/' . Util::slugify($filenameWithoutExtension) . '.' . $ext; $image = new ZebraImage(); $image->jpeg_quality = 100; $image->chmod_value = 0755; $image->source_path = $newFileName; $image->target_path = $newThumbnailName; $image->resize(150, 150, ZEBRA_IMAGE_CROP_CENTER); } return new JsonResponse($attachmentId); } return new Response(''); }
public function indexAction(Request $request, SessionInterface $session) { $userId = $session->get('user/id'); $uploadPath = UbirimiContainer::get()['asset.root_folder'] . UbirimiContainer::get()['asset.user_avatar'] . $userId; if (!file_exists($uploadPath)) { mkdir($uploadPath); } if (UPLOAD_ERR_OK == $_FILES["files"]["error"][0]) { $tmp_name = $_FILES["files"]["tmp_name"][0]; $name = $_FILES["files"]["name"][0]; $extension = Util::getExtension($name); if ($extension != 'png' && $extension != 'jpg' && $extension != 'jpeg') { return new Response('error'); } $filename = 'user_' . $userId; $originalFileName = $filename . "." . $extension; move_uploaded_file($tmp_name, $uploadPath . "/" . $originalFileName); $this->getRepository(UbirimiUser::class)->updateAvatar($originalFileName, $userId); $newFileName = $uploadPath . "/" . $originalFileName; $newThumbnailName = $uploadPath . "/" . $filename . '_150.' . $extension; $image = new ZebraImage(); $image->jpeg_quality = 100; $image->chmod_value = 0755; $image->source_path = $newFileName; $image->target_path = $newThumbnailName; $image->resize(150, 150, ZEBRA_IMAGE_CROP_CENTER); $newThumbnailName = $uploadPath . "/" . $filename . '_33.' . $extension; $image = new ZebraImage(); $image->jpeg_quality = 100; $image->chmod_value = 0755; $image->source_path = $newFileName; $image->target_path = $newThumbnailName; $image->resize(33, 33, ZEBRA_IMAGE_CROP_CENTER); $session->set('user/avatar_picture', $filename . '.' . $extension); return new Response($userId . '/' . $originalFileName); } }