public function find($path) { $imageFile = file_get_contents($path); if (!$imageFile) { throw new NotLoadableException(sprintf('Source image not found in "%s"', $path)); } $mimeType = image_type_to_mime_type(exif_imagetype($path)); //var_dump($mimeType);die(); return new Binary($imageFile, $mimeType, $this->extensionGuesser->guess($mimeType)); }
/** * @param $value * @param Constraint $constraint * * @throws ConstraintDefinitionException * @throws UnexpectedTypeException */ public function validate($value, Constraint $constraint) { if (!$constraint instanceof HasGuessableExtension) { throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\\HasGuessableExtension'); } if (!$value instanceof UploadedFile) { return; } $contentType = $this->mimeTypeGuesser->guess($value->getPathname()); $pathInfo = pathinfo($value->getClientOriginalName()); if (!array_key_exists('extension', $pathInfo)) { $pathInfo['extension'] = $this->extensionGuesser->guess($contentType); } if ($pathInfo['extension'] === NULL) { $this->context->buildViolation($constraint->notGuessableErrorMessage)->setCode(HasGuessableExtension::NOT_GUESSABLE_ERROR)->addViolation(); } }