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 deleteByIssueId($issueId) { $attachments = IssueAttachment::getByIssueId($issueId); if ($attachments) { while ($attachment = $attachments->fetch_array(MYSQLI_ASSOC)) { $attachmentId = $attachment['id']; unlink(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId . '/' . $attachmentId . '/' . $attachment['name']); if (Util::isImage(Util::getExtension($attachment['name']))) { unlink(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId . '/' . $attachmentId . '/thumbs/' . $attachment['name']); Util::deleteDir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId . '/' . $attachmentId . '/thumbs'); } Util::deleteDir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId . '/' . $attachmentId); } // also delete the folder if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId)) { Util::deleteDir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId); } } }
public function indexAction(Request $request, SessionInterface $session) { Util::checkUserIsLoggedInAndRedirect(); $attachmentId = $request->request->get('att_id'); $attachment = $this->getRepository(IssueAttachment::class)->getById($attachmentId); $this->getRepository(IssueAttachment::class)->deleteById($attachmentId); $pathToAttachment = UbirimiContainer::get()['asset.root_folder'] . UbirimiContainer::get()['asset.yongo_issue_attachments']; unlink($pathToAttachment . $attachment['issue_id'] . '/' . $attachment['id'] . '/' . $attachment['name']); if (Util::isImage(Util::getExtension($attachment['name']))) { unlink($pathToAttachment . $attachment['issue_id'] . '/' . $attachment['id'] . '/thumbs/' . $attachment['name']); Util::deleteDir($pathToAttachment . $attachment['issue_id'] . '/' . $attachment['id'] . '/thumbs'); } Util::deleteDir($pathToAttachment . $attachment['issue_id'] . '/' . $attachment['id']); // delete the issue folder if necessary if (2 == count(scandir($pathToAttachment . $attachment['issue_id']))) { Util::deleteDir($pathToAttachment . $attachment['issue_id']); } return new Response(''); }
} ?> <?php } ?> </table> </td> </tr> <tr> <td> <table width="100%"> <?php foreach ($attachments as $attachment) { ?> <?php if (!Util::isImage(Util::getExtension($attachment['name']))) { ?> <tr> <td width="75%"> <a target="_blank" href="/assets<?php echo UbirimiContainer::get()['asset.yongo_issue_attachments'] . $attachment['issue_id'] . '/' . $attachment['id'] . '/' . $attachment['name']; ?> "> <?php echo $attachment['name']; ?> </a> </td> <td> <?php echo round($attachment['size'] / 1024, 2);
public static function manageModalAttachments($issueId, $loggedInUserId, $attachIdsToBeKept) { if (null != UbirimiContainer::get()['session']->has('added_attachments_in_screen')) { $attIdsSession = UbirimiContainer::get()['session']->get('added_attachments_in_screen'); $uploadDirectory = Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId; for ($i = 0; $i < count($attIdsSession); $i++) { $attachmentId = $attIdsSession[$i]; $attachment = UbirimiContainer::get()['repository']->get(IssueAttachment::class)->getById($attachmentId); if (!in_array($attachmentId, $attachIdsToBeKept)) { // the attachment must be deleted UbirimiContainer::get()['repository']->get(IssueAttachment::class)->deleteById($attachmentId); if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $attachment['issue_id'] . '/' . $attachment['id'] . '/' . $attachment['name'])) { unlink(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $attachment['issue_id'] . '/' . $attachment['id'] . '/' . $attachment['name']); if (Util::isImage(Util::getExtension($attachment['name']))) { if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $attachment['issue_id'] . '/' . $attachment['id'] . '/thumbs/' . $attachment['name'])) { unlink(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $attachment['issue_id'] . '/' . $attachment['id'] . '/thumbs/' . $attachment['name']); Util::deleteDir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $attachment['issue_id'] . '/' . $attachment['id'] . '/thumbs'); } } } if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $attachment['issue_id'] . '/' . $attachment['id'])) { Util::deleteDir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $attachment['issue_id'] . '/' . $attachment['id']); } // deal with the user_ folders if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id'] . '/' . $attachment['name'])) { unlink(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id'] . '/' . $attachment['name']); if (Util::isImage(Util::getExtension($attachment['name']))) { if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id'] . '/thumbs/' . $attachment['name'])) { unlink(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id'] . '/thumbs/' . $attachment['name']); Util::deleteDir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id'] . '/thumbs'); } } } if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id'])) { Util::deleteDir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id']); } } else { if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id'] . '/' . $attachment['name'])) { if (!file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId)) { // create the moder mkdir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId); } // move the attachment rename(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId . '/' . $attachment['id'], Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . $issueId . '/' . $attachment['id']); // update the attachment UbirimiContainer::get()['repository']->get(IssueAttachment::class)->updateByIdAndIssueId($attachmentId, $issueId); } } } if (file_exists($uploadDirectory) && count(scandir($uploadDirectory)) == 2) { Util::deleteDir($uploadDirectory); } if (file_exists(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId)) { Util::deleteDir(Util::getAssetsFolder(SystemProduct::SYS_PRODUCT_YONGO) . 'user_' . $loggedInUserId); } } }