當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。