/**
  * (non-PHPdoc)
  * @see PartKeepr\Service.RestfulService::create()
  */
 public function create()
 {
     $this->requireParameter("tmp_id");
     $this->requireParameter("project_id");
     $tmpImage = TempUploadedFile::loadById($this->getParameter("tmp_id"));
     $file = new ProjectAttachment();
     $project = Project::loadById($this->getParameter("project_id"));
     $file->setProject($project);
     $file->replace($tmpImage->getFilename());
     $file->setOriginalFilename($tmpImage->getOriginalFilename());
     $file->setDescription($this->getParameter("description"));
     PartKeepr::getEM()->persist($file);
     PartKeepr::getEM()->flush();
     return $file->serialize();
 }
예제 #2
0
 private function processAttachmentChanges(Part $part, array $data)
 {
     if (array_key_exists("updates", $data)) {
         foreach ($data["updates"] as $record) {
             foreach ($part->getAttachments() as $partAttachment) {
                 if ($partAttachment->getId() == $record["id"]) {
                     $partAttachment->setDescription($record["description"]);
                     break;
                 }
             }
         }
     }
     if (array_key_exists("removals", $data)) {
         foreach ($data["removals"] as $record) {
             foreach ($part->getAttachments() as $partAttachment) {
                 if ($partAttachment->getId() == $record["id"]) {
                     PartKeepr::getEM()->remove($partAttachment);
                     $part->getAttachments()->removeElement($partAttachment);
                     break;
                 }
             }
         }
     }
     if (array_key_exists("inserts", $data)) {
         foreach ($data["inserts"] as $record) {
             $attachment = new PartAttachment();
             $attachment->setPart($part);
             $attachment->setDescription($record["description"]);
             $file = TempUploadedFile::loadById($record["tmp_id"]);
             $attachment->replace($file->getFilename());
             $attachment->setOriginalFilename($file->getOriginalFilename());
             $part->getAttachments()->add($attachment);
         }
     }
 }
예제 #3
0
            case "Print":
                $file = TempUploadedFile::loadById($id);
                break;
            default:
                $file = null;
                // Add default image?
        }
    } catch (\Exception $e) {
        $file = null;
        // Something bad happened
    }
}
if ($file == null) {
    // Could not find the image, but maybe we want a temporary image?
    if (array_key_exists("tmpId", $_REQUEST)) {
        $file = TempUploadedFile::loadById($_REQUEST["tmpId"]);
    }
}
if (is_object($file)) {
    header("Content-Type: " . $file->getMimeType());
    if (array_key_exists("download", $_REQUEST) && $_REQUEST["download"] == "true") {
        header("Content-Description: File Transfer");
        header('Content-Disposition: attachment; filename="' . basename($file->getOriginalFilename()) . '"');
    } else {
        header('Content-Disposition: inline; filename="' . basename($file->getOriginalFilename()) . '"');
    }
    $fp = fopen($file->getFilename(), "rb");
    fpassthru($fp);
    fclose($fp);
} else {
    echo "404 not found";
예제 #4
0
 /**
  * Replaces the file with a given temporary file.
  * @param string $id The temporary id (prefixed with TMP:)
  */
 public function replaceFromTemporaryFile($id)
 {
     if (substr($id, 0, 4) === "TMP:") {
         $tmpFileId = str_replace("TMP:", "", $id);
         $tmpFile = TempUploadedFile::loadById($tmpFileId);
         $this->replace($tmpFile->getFilename());
         $this->setOriginalFilename($tmpFile->getOriginalFilename());
     }
 }