当前位置: 首页>>代码示例>>PHP>>正文


PHP UploadedFile::getClientMimeType方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\File\UploadedFile::getClientMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getClientMimeType方法的具体用法?PHP UploadedFile::getClientMimeType怎么用?PHP UploadedFile::getClientMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpFoundation\File\UploadedFile的用法示例。


在下文中一共展示了UploadedFile::getClientMimeType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: importFromFile

 /**
  * Import file and find Stories inside
  * This method will select automatically the best way to find stories
  * depending the kind of file uploaded
  *
  * @param UploadedFile $file XML or XLS file from Jira
  * @return bool True if stories found, False in the other case
  */
 public function importFromFile(UploadedFile $file)
 {
     if ('text/xml' === $file->getClientMimeType() or 'text/html' === $file->getClientMimeType()) {
         $this->importFromXML($file);
     } elseif ('application/octet-stream' === $file->getClientMimeType() or 'application/vnd.ms-excel' === $file->getClientMimeType() or 'application/msexcel' === $file->getClientMimeType() or 'application/x-msexcel' === $file->getClientMimeType() or 'application/x-ms-excel' === $file->getClientMimeType() or 'application/x-excel' === $file->getClientMimeType() or 'application/x-dos_ms_excel' === $file->getClientMimeType() or 'application/xls' === $file->getClientMimeType() or 'application/x-xls' === $file->getClientMimeType() or 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' === $file->getClientMimeType()) {
         /* 
         Because mine type detection doesn't work perfectly, at this time we don't know
         if the file is a classic XLS or a HTML XLS (XLSx)
         
         First we try to analyse it as a classical XLS file, if the file isn't an XLS file
         an exception will be thrown and we will try to check it as an HTML file (Jira HTML).
         
         Finally if the file isn't an Excel or a Jira HTML File an exception will be thrown
         and has to be catch by the parent method.
         */
         try {
             $this->importFromXLS($file);
         } catch (\Exception $e) {
             $this->importFromHTML($file);
         }
     } else {
         // Delete the temporary file
         unlink($file->getRealPath());
         throw new \Symfony\Component\HttpFoundation\File\Exception\FileException();
     }
     // Delete the temporary file
     unlink($file->getRealPath());
     if (count($this->stories->getStories()) > 0) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:primeminister,项目名称:AgileStoryPrint,代码行数:41,代码来源:StoryCard.php

示例2: makeFileRecord

 /**
  * Create a base file model class
  *
  * @return File
  */
 protected function makeFileRecord()
 {
     $file = new File();
     $file->fileable_type = $this->fileable_type;
     $file->fileable_id = $this->fileable_id;
     $file->filename = $this->timestamp . '-' . $this->file->getClientOriginalName();
     $file->filetype = $this->file->getClientMimeType();
     $file->filepath = $file->getURLPath() . $file->filename;
     $file->order = 0;
     return $file;
 }
开发者ID:grlf,项目名称:laravel-portal-template,代码行数:16,代码来源:StoreFileableFiles.php

示例3: upload

 public function upload(UploadedFile $file, $path)
 {
     // Check if the file's mime type is in the list of allowed mime types.
     if (!in_array($file->getClientMimeType(), self::$allowedMimeTypes)) {
         throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getClientMimeType()));
     }
     $adapter = $this->filesystem->getAdapter();
     $adapter->setMetadata($path, array('contentType' => $file->getClientMimeType()));
     $adapter->write($path, file_get_contents($file->getPathname()));
     return $path;
 }
开发者ID:Zacklane,项目名称:expensesManager,代码行数:11,代码来源:ImageUploader.php

示例4: upload

 public function upload(UploadedFile $file, $path = null)
 {
     // Check if the file's mime type is in the list of allowed mime types.
     if (!in_array($file->getClientMimeType(), self::$allowedMimeTypes)) {
         throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $file->getClientMimeType()));
     }
     if ($path) {
         $filename = sprintf('%s/%s.%s', $path, md5(time() * rand(0, 99)), $file->getClientOriginalExtension());
     } else {
         $filename = sprintf('%s/%s/%s/%s.%s', date('Y'), date('m'), date('d'), md5(time() * rand(0, 99)), $file->getClientOriginalExtension());
     }
     $adapter = $this->filesystem->getAdapter();
     $adapter->setMetadata($filename, array('contentType' => $file->getClientMimeType()));
     $adapter->write($filename, file_get_contents($file->getPathname()));
     return $filename;
 }
开发者ID:webdeveloper258,项目名称:amazons3bundle,代码行数:16,代码来源:FileManager.php

示例5: handle

 /**
  * Handle the file upload. Returns the array on success, or false
  * on failure.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  * @param String $path where to upload file
  * @return array|bool
  */
 public function handle(UploadedFile $file, $path = 'uploads')
 {
     $input = array();
     $fileName = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME));
     // Detect and transform Croppa pattern to avoid problem with Croppa::delete()
     $fileName = preg_replace('#([0-9_]+)x([0-9_]+)#', "\$1-\$2", $fileName);
     $input['path'] = $path;
     $input['extension'] = '.' . $file->getClientOriginalExtension();
     $input['filesize'] = $file->getClientSize();
     $input['mimetype'] = $file->getClientMimeType();
     $input['filename'] = $fileName . $input['extension'];
     $fileTypes = Config::get('file.types');
     $input['type'] = $fileTypes[strtolower($file->getClientOriginalExtension())];
     $filecounter = 1;
     while (file_exists($input['path'] . '/' . $input['filename'])) {
         $input['filename'] = $fileName . '_' . $filecounter++ . $input['extension'];
     }
     try {
         $file->move($input['path'], $input['filename']);
         list($input['width'], $input['height']) = getimagesize($input['path'] . '/' . $input['filename']);
         return $input;
     } catch (FileException $e) {
         Notification::error($e->getmessage());
         return false;
     }
 }
开发者ID:phillipmadsen,项目名称:app,代码行数:34,代码来源:FileUpload.php

示例6: getFileArray

 /**
  * converts UploadedFile to $_FILES array
  *
  * @return array
  */
 public function getFileArray()
 {
     $array = array('name' => $this->uploaded_file->getClientOriginalName(), 'type' => $this->uploaded_file->getClientMimeType(), 'tmp_name' => $this->uploaded_file->getPath() . $this->getOSDirectorySeparator() . $this->uploaded_file->getFilename(), 'error' => $this->uploaded_file->getError(), 'size' => $this->uploaded_file->getSize(), 'dimension' => array('width' => 0, 'height' => 0));
     if (preg_match('/^image/', $array['type'])) {
         list($array['dimension']['width'], $array['dimension']['height']) = getimagesize($this->uploaded_file);
     }
     return $array;
 }
开发者ID:RSSfeed,项目名称:UploadBundle,代码行数:13,代码来源:HandleUpload.php

示例7: createFromFile

 /**
  * Create a file row from the given file
  * @param  UploadedFile $file
  * @return mixed
  */
 public function createFromFile(UploadedFile $file)
 {
     $fileName = FileHelper::slug($file->getClientOriginalName());
     $exists = $this->model->whereFilename($fileName)->first();
     if ($exists) {
         throw new \InvalidArgumentException('File slug already exists');
     }
     return $this->model->create(['filename' => $fileName, 'path' => "/assets/media/{$fileName}", 'extension' => $file->guessClientExtension(), 'mimetype' => $file->getClientMimeType(), 'filesize' => $file->getFileInfo()->getSize()]);
 }
开发者ID:nmpribeiro,项目名称:Media,代码行数:14,代码来源:EloquentFileRepository.php

示例8: createMediaFromUploadedFile

 /**
  * @param UploadedFile $file
  *
  * @return \WellCommerce\Bundle\MediaBundle\Entity\MediaInterface
  */
 protected function createMediaFromUploadedFile(UploadedFile $file)
 {
     $media = $this->initResource();
     $media->setName($file->getClientOriginalName());
     $media->setExtension($file->guessClientExtension());
     $media->setMime($file->getClientMimeType());
     $media->setSize($file->getClientSize());
     return $media;
 }
开发者ID:Newman101,项目名称:WellCommerce,代码行数:14,代码来源:MediaManager.php

示例9: createFromFile

 /**
  * Create a file row from the given file
  * @param  UploadedFile $file
  * @return mixed
  */
 public function createFromFile(UploadedFile $file)
 {
     $fileName = FileHelper::slug($file->getClientOriginalName());
     $exists = $this->model->whereFilename($fileName)->first();
     if ($exists) {
         $fileName = $this->getNewUniqueFilename($fileName);
     }
     return $this->model->create(['filename' => $fileName, 'path' => config('asgard.media.config.files-path') . "{$fileName}", 'extension' => substr(strrchr($fileName, "."), 1), 'mimetype' => $file->getClientMimeType(), 'filesize' => $file->getFileInfo()->getSize(), 'folder_id' => 0]);
 }
开发者ID:mahmouddev,项目名称:Media,代码行数:14,代码来源:EloquentFileRepository.php

示例10: getFileFromChunks

 /**
  * Check if all chunks of a file being uploaded have been received
  * If yes, return the name of the reassembled temporary file
  *
  * @param UploadedFile $uploadedFile
  *
  * @return UploadedFile|null
  */
 public function getFileFromChunks(UploadedFile $uploadedFile)
 {
     $filename = time() . '-' . $uploadedFile->getClientOriginalName();
     $path = $this->tmpDir . DIRECTORY_SEPARATOR . $filename;
     if (FlowBasic::save($path, $this->tmpDir)) {
         return new UploadedFile($path, $uploadedFile->getClientOriginalName(), $uploadedFile->getClientMimeType());
     }
     return null;
 }
开发者ID:open-orchestra,项目名称:open-orchestra-media-admin-bundle,代码行数:17,代码来源:SaveMediaManager.php

示例11: setupFile

 /**
  * Setup image file
  *
  * @param UploadedFile $file
  * @param string       $style_guide
  */
 public function setupFile(UploadedFile $file, $style_guide = null)
 {
     $this->_source = $file;
     $this->setFileExtension($file->getClientOriginalExtension());
     $this->setFileNameAttribute($file->getClientOriginalName());
     $this->setMimeTypeAttribute($file->getClientMimeType());
     $this->setFileSizeAttribute($file->getSize());
     if (!empty($style_guide)) {
         $this->setStyleGuideName($style_guide);
     }
 }
开发者ID:pablolovera,项目名称:attacher,代码行数:17,代码来源:AttacherModel.php

示例12: save

 /**
  * {@inheritdoc}
  */
 public function save(UploadedFile $file, $dir)
 {
     $media = new Media();
     $media->setName($file->getClientOriginalName());
     $media->setExtension($file->guessClientExtension());
     $media->setMime($file->getClientMimeType());
     $media->setSize($file->getClientSize());
     $this->_em->persist($media);
     $this->_em->flush();
     return $media;
 }
开发者ID:raizeta,项目名称:WellCommerce,代码行数:14,代码来源:MediaRepository.php

示例13: createDbData

 /**
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  *
  * @return array
  */
 private function createDbData(UploadedFile $file, $completedPath, $propertyId)
 {
     $data = [];
     $type = $file->getClientMimeType();
     $fileName = $file->getClientOriginalName();
     $data["type"] = $type;
     $data["path"] = $completedPath;
     // TODO: need to fix for different storage location
     $data["link"] = "/files/" . urlencode(str_replace(public_path() . "/files/", "", $completedPath));
     $data["fileName"] = $fileName;
     $data["property_id"] = $propertyId;
     return $data;
 }
开发者ID:xavierauana,项目名称:avaluestay,代码行数:18,代码来源:MediaManagementServices.php

示例14: createFromObject

 /**
  * Build a \Torann\MediaSort\File\UploadedFile object from
  * a Symfony\Component\HttpFoundation\File\UploadedFile object.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  *
  * @return \Torann\MediaSort\File\UploadedFile
  * @throws \Torann\MediaSort\Exceptions\FileException
  */
 protected function createFromObject(SymfonyUploadedFile $file)
 {
     $path = $file->getPathname();
     $originalName = $file->getClientOriginalName();
     $mimeType = $file->getClientMimeType();
     $size = $file->getClientSize();
     $error = $file->getError();
     $uploadFile = new UploadedFile($path, $originalName, $mimeType, $size, $error);
     if (!$uploadFile->isValid()) {
         throw new FileException($uploadFile->getErrorMessage($uploadFile->getError()));
     }
     return $uploadFile;
 }
开发者ID:torann,项目名称:mediasort,代码行数:22,代码来源:FileManager.php

示例15: upload

 /**
  * Upload new attachment
  *
  * @param UploadedFile $file
  * @param string       $descriptionText
  * @param Language     $language
  * @param array        $attributes
  * @param Attachment   $attachment
  *
  * @return Attachment
  */
 public function upload(UploadedFile $file, $descriptionText, Language $language, array $attributes, Attachment $attachment = null)
 {
     $filesystem = new Filesystem();
     $filesize = $file->getClientSize();
     if ($filesize == false) {
         throw new FileException('File size is not valid');
     }
     if (!file_exists($this->config['file_directory']) || !is_writable($this->config['file_directory'])) {
         throw new FileException('Directory ' . $this->config['file_directory'] . ' is not writable');
     }
     if (!is_null($attachment)) {
         if ($filesystem->exists($this->getStorageLocation($attachment))) {
             $filesystem->remove($this->getStorageLocation($attachment));
         }
         if ($descriptionText != $attachment->getDescription()->getTranslationText()) {
             $nextTranslationPhraseId = $this->em->getRepository('Newscoop\\Entity\\AutoId')->getNextTranslationPhraseId();
             $description = new Translation($nextTranslationPhraseId);
             $description->setLanguage($language);
             $description->setTranslationText($descriptionText);
             $this->em->persist($description);
         }
         unset($attributes['description']);
     } else {
         $attachment = new Attachment();
         $nextTranslationPhraseId = $this->em->getRepository('Newscoop\\Entity\\AutoId')->getNextTranslationPhraseId();
         $description = new Translation($nextTranslationPhraseId);
         $description->setLanguage($language);
         $description->setTranslationText($descriptionText);
         unset($attributes['description']);
         $attachment->setCreated(new \DateTime());
         $this->em->persist($description);
         $this->em->persist($attachment);
     }
     $attributes = array_merge(array('language' => $language, 'name' => $file->getClientOriginalName(), 'extension' => $file->getClientOriginalExtension(), 'mimeType' => $file->getClientMimeType(), 'contentDisposition' => Attachment::CONTENT_DISPOSITION, 'sizeInBytes' => $file->getClientSize(), 'description' => $description), $attributes);
     $this->fillAttachment($attachment, $attributes);
     if (is_null($attributes['name'])) {
         $attachment->setName($file->getClientOriginalName());
     }
     $this->em->flush();
     $target = $this->makeDirectories($attachment);
     try {
         $file->move($target, $this->getFileName($attachment));
         $filesystem->chmod($target . '/' . $this->getFileName($attachment), 0644);
     } catch (\Exceptiom $e) {
         $filesystem->remove($target);
         $this->em->remove($attachment);
         $this->em->flush();
         throw new \Exception($e->getMessage(), $e->getCode());
     }
     return $attachment;
 }
开发者ID:sourcefabric,项目名称:newscoop,代码行数:62,代码来源:AttachmentService.php


注:本文中的Symfony\Component\HttpFoundation\File\UploadedFile::getClientMimeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。