Nette\Http\FileUpload::isImage PHP Метод

isImage() публичный Метод

Is uploaded file GIF, PNG or JPEG?
public isImage ( ) : boolean
Результат boolean
    public function isImage()
    {
        return in_array($this->getContentType(), ['image/gif', 'image/png', 'image/jpeg'], TRUE);
    }

Usage Example

Пример #1
0
 /**
  * @param FileUpload $file
  * @return Image
  * @throws NotImageUploadedException
  * @throws FileSizeException
  * @throws DBALException
  * @throws InvalidStateException
  */
 public function processImage(FileUpload $file)
 {
     if (!$file->isImage()) {
         throw new NotImageUploadedException();
     }
     if (\filesize($file->getTemporaryFile()) > Image::MAX_FILE_SIZE) {
         throw new FileSizeException();
     }
     try {
         $this->em->beginTransaction();
         $image = new Image($file);
         $this->em->persist($image)->flush();
         $file->move($this->composeImageLocation($image));
         $this->em->commit();
     } catch (InvalidStateException $is) {
         $this->em->rollback();
         $this->em->close();
         $this->logger->addError('Error occurs while moving temp. image file to new location.');
         throw $is;
     } catch (DBALException $e) {
         $this->em->rollback();
         $this->em->close();
         $this->logger->addError('Image error');
         // todo err message
         throw $e;
     }
     return $image;
 }
All Usage Examples Of Nette\Http\FileUpload::isImage