Ejemplo n.º 1
0
 public function upload()
 {
     $image = new TempImage();
     if (array_key_exists("userfile", $_FILES) && file_exists($_FILES["userfile"]["tmp_name"])) {
         $file = $_FILES['userfile']['tmp_name'];
         $filename = $_FILES['userfile']['name'];
         $image->replace($file);
         $image->setOriginalFilename(basename($filename));
     } elseif (array_key_exists("url", $_REQUEST)) {
         $image->replaceFromURL($_REQUEST["url"]);
     } else {
         throw new \Exception("Error: No valid file given");
     }
     PartKeepr::getEM()->persist($image);
     PartKeepr::getEM()->flush();
     return array("id" => $image->getId(), "extension" => $image->getExtension(), "size" => $image->getSize(), "originalFilename" => $image->getOriginalFilename());
 }
 /**
  * (non-PHPdoc)
  * @see PartKeepr\Service.RestfulService::create()
  */
 public function create()
 {
     $this->requireParameter("tmp_id");
     $this->requireParameter("manufacturer_id");
     $tmpImage = TempImage::loadById($this->getParameter("tmp_id"));
     $image = new ManufacturerICLogo();
     $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id"));
     $image->setManufacturer($manufacturer);
     $image->replace($tmpImage->getFilename());
     $image->setOriginalFilename($tmpImage->getOriginalFilename());
     PartKeepr::getEM()->persist($image);
     PartKeepr::getEM()->flush();
     return $image->serialize();
 }
Ejemplo n.º 3
0
                $image = new PartImage();
                $image->replace($attachment->getFilename());
                break;
            default:
                $image = null;
                // Add default image?
        }
    } catch (\Exception $e) {
        $image = null;
        // Something bad happened
    }
}
if ($image == null) {
    // Could not find the image, but maybe we want a temporary image?
    if (array_key_exists("tmpId", $_REQUEST)) {
        $image = TempImage::loadById($_REQUEST["tmpId"]);
    }
    if ($image === null) {
        /* The image is still null - output an "image not found" image.	 */
        ImageRenderer::outputRenderNotFoundImage($_REQUEST["w"], $_REQUEST["h"]);
        exit;
    }
}
$mode = "fit";
if (array_key_exists("m", $_REQUEST)) {
    $mode = $_REQUEST["m"];
}
if (array_key_exists("cache", $_REQUEST)) {
    if ($_REQUEST["cache"] == "false") {
        CachedImage::invalidate($image);
    }
Ejemplo n.º 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 = TempImage::loadById($tmpFileId);
         $this->replace($tmpFile->getFilename());
         $this->setOriginalFilename($tmpFile->getOriginalFilename());
     }
 }