/** * creates a new uploader-instance. * * @throws \DripsPHP\Converter\UnitNotFoundException */ public function __construct() { parent::__construct(); $this->filetypes = array('pdf'); }
<?php define("VENDOR_SRC", __DIR__ . "/vendor"); define("AUTOLOAD_FILE", VENDOR_SRC . "/autoload.php"); require_once AUTOLOAD_FILE; use Drips\Uploader\Uploader; use Drips\HTTP\Request; $request = new Request(); $uploader = new Uploader(); $path_parts = explode("/", $_SERVER['SCRIPT_FILENAME']); array_pop($path_parts); $upload_dir = implode("/", $path_parts) . "/uploaded_files"; if ($request->isPut()) { //Pretend $name is the filename specified in the put url $name = "test.txt"; $uploader->upload($name, $upload_dir); } elseif ($request->isPost()) { $uploader->upload("data", $upload_dir); }
/** * check function for filetype, filesize, and other restrictions. * * @param $file * * @return bool * * @throws UploadFileImageIsToBigException * @throws UploadFileIsToBigException * @throws UploadFiletypeNotAllowedException */ public function checkFile($file) { if (parent::checkFile($file)) { // is image upload? if (!$this->isAllowedImageSize($file['tmpname'])) { throw new UploadFileImageIsToBigException($this->imgWidth . 'x' . $this->imgHeight); } if (!$this->isAllowedMinImageSize($file['tmpname'])) { throw new UploadFileImageIsToSmallException($this->imgWidth . 'x' . $this->imgHeight); } } return true; }