Exemplo n.º 1
0
 public static function getFile($blueprint, $field, $id)
 {
     $tag = "Binary::getFile()";
     Log::debug("{$tag}");
     try {
         $binaryString = Binary::getString($blueprint, $field, $id);
     } catch (Exception $e) {
         throw $e;
     }
     $tmpFile = tmpfile();
     $bytes = fwrite($tmpFile, $binaryString);
     if ($bytes) {
         return $tmpFile;
     } else {
         Log::error("{$tag}: Unable to write to temporary file");
         throw new Exception("{$tag}: Unable to write to temporary file");
     }
 }
Exemplo n.º 2
0
             }
         } else {
             // No file was uploaded for this binary field;
             Log::debug("...No file found");
             if ($entityId != 0) {
                 // Existing Entity
                 if (array_key_exists($key, $_POST) && $_POST[$key] == "clear") {
                     // Process request to clear binary
                     Log::debug("...Clear binary");
                     $entity->set($key, NULL);
                     $entity->length($key, 0);
                 } else {
                     // Keep current binaries for existing entities
                     Log::debug("...Keep existing binary");
                     if ($entity->length($key) > 0) {
                         $entity->set($key, Binary::getString($entityBP->getKey(), $key, $entity->getId()));
                         // this is required since this field could have been over written by init($_POST)
                     } else {
                         $entity->set($key, NULL);
                         // this is required since this field could have been over written by init($_POST)
                     }
                 }
             } else {
                 // New Entity
                 $entity->set($key, NULL);
                 $entity->length($key, 0);
             }
         }
     }
     // END: if($field->getDataType() == "binary")
 }
Exemplo n.º 3
0
if (empty($blueprint) || empty($field) || empty($id)) {
    Log::error("Missing a required input");
    echo "ERROR: Missing a required input.";
    exit;
} else {
    Log::debug("... " . $blueprint . "." . $field . ": " . $id);
    try {
        // load the blueprint
        $blueprint_file_name = $blueprint . ".entity.xml";
        $bp = BlueprintReader::read($blueprint_file_name);
        // lookup the field
        $f = $bp->get($field);
        // retrieve meta data for file creation
        $mimeType = $f->getMimeType();
        // retrieve the binary as a string
        $binaryString = Binary::getString($blueprint, $field, $id);
    } catch (Exception $e) {
        Log::error($e->getMessage());
        echo "EXCEPTION: " . $e->getMessage();
        exit;
    }
    switch ($action) {
        case "file":
            // create filename
            $ext = Binary::extension($mimeType);
            $filename = $blueprint . "." . $field . "." . $id . "." . $ext;
            // set headers
            header("Content-Type: {$mimeType}");
            header("Content-Disposition: attachment; filename={$filename}");
            header("Content-Transfer-Encoding: binary");
            echo "{$binaryString}";