當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::getBasename方法代碼示例

本文整理匯總了PHP中Symfony\Component\HttpFoundation\File\File::getBasename方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::getBasename方法的具體用法?PHP File::getBasename怎麽用?PHP File::getBasename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\HttpFoundation\File\File的用法示例。


在下文中一共展示了File::getBasename方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getFilename

 /**
  * Calculate the filename of the resultant file or version.
  *
  * @param File        $original The original file
  * @param string|null $version  The name of the version, or null
  *
  * @return string The resultant filename
  */
 public function getFilename(File $original, $version = null)
 {
     if (is_null($version)) {
         return $original->getBasename();
     }
     $extension = $original->getExtension();
     $base = $original->getBasename($extension);
     return $base . $version . '.' . $extension;
 }
開發者ID:clarkf,項目名稱:hitch,代碼行數:17,代碼來源:Uploader.php

示例2: updateImage

 /**
  * @param \Exolnet\Image\Image                        $image
  * @param \Symfony\Component\HttpFoundation\File\File $file
  */
 public function updateImage(Image $image, File $file)
 {
     $this->destroy($image);
     $fileName = $image->getId() . '-' . Str::slug($file->getBasename()) . '.' . $file->guessExtension();
     $image->setFilename($fileName);
     $image->save();
     $this->store($image, $file);
 }
開發者ID:eXolnet,項目名稱:laravel-image,代碼行數:12,代碼來源:ImageService.php

示例3: __construct

 /**
  * Constructor.
  *
  * @param File $file A File instance
  */
 public function __construct(File $file)
 {
     if ($file instanceof UploadedFile) {
         parent::__construct($file->getPathname(), $file->getClientOriginalName(), $file->getClientMimeType(), $file->getClientSize(), $file->getError(), true);
     } else {
         parent::__construct($file->getPathname(), $file->getBasename(), $file->getMimeType(), $file->getSize(), 0, true);
     }
 }
開發者ID:sfblaauw,項目名稱:pulsar-uploader,代碼行數:13,代碼來源:FilesystemFile.php

示例4: __construct

 /**
  * @param string|null $pathname
  */
 public function __construct($pathname = null)
 {
     $this->pathname = $pathname;
     if ($pathname) {
         $file = new SfFile($pathname);
         $this->name = $file->getBasename();
         $this->id = $this->name;
         $this->mimeType = $file->getMimeType();
         $this->size = $file->getSize();
     }
 }
開發者ID:kgilden,項目名稱:php-digidoc,代碼行數:14,代碼來源:File.php

示例5: replaceFromFilesystem

 /**
  * Replaces the current file with a new file.
  *
  * @param UploadedFile $file           The target file
  * @param File         $filesystemFile The source file
  */
 public function replaceFromFilesystem(UploadedFile $file, File $filesystemFile)
 {
     $file->setOriginalFilename($filesystemFile->getBasename());
     $file->setExtension($filesystemFile->getExtension());
     $file->setMimeType($filesystemFile->getMimeType());
     $file->setSize($filesystemFile->getSize());
     $storage = $this->getStorage($file);
     if ($filesystemFile->getSize() > $this->container->get("partkeepr_systemservice")->getFreeDiskSpace()) {
         throw new DiskSpaceExhaustedException();
     }
     $storage->write($file->getFullFilename(), file_get_contents($filesystemFile->getPathname()), true);
 }
開發者ID:fulcrum3d,項目名稱:PartKeepr,代碼行數:18,代碼來源:UploadedFileService.php

示例6: VisualAction

 public function VisualAction($document)
 {
     // Generate response
     $response = new Response();
     // Set headers
     $filepath = $this->get('kernel')->getRootDir() . "/uploads/formations_documents/" . $document;
     $oFile = new File($filepath);
     $response->headers->set('Cache-Control', 'private');
     $response->headers->set('Content-type', $oFile->getMimeType());
     $response->headers->set('Content-Disposition', 'inline; filepath="' . $oFile->getBasename() . '";');
     $response->headers->set('Content-length', $oFile->getSize());
     // filename
     // Send headers before outputting anything
     $response->sendHeaders();
     $response->setContent(file_get_contents($filepath));
     return $response;
 }
開發者ID:WildCodeSchool,項目名稱:partnet,代碼行數:17,代碼來源:FormationsController.php

示例7: uploadByPath

 /**
  * Upload local file to storage
  *
  * @access public
  * @param  mixed  $pathname
  * @param  bool   $unlinkAfterUpload (default: true)
  * @return string
  */
 public function uploadByPath($pathname, $unlinkAfterUpload = true)
 {
     $file = new File($pathname);
     $filename = $file->getBasename();
     $fileMimeType = $file->getMimeType();
     if ($this->allowedTypes && !in_array($fileMimeType, $this->allowedTypes)) {
         throw new \InvalidArgumentException(sprintf('Files of type %s are not allowed.', $fileMimeType));
     }
     $adapter = $this->filesystem->getAdapter();
     if (!$adapter instanceof Local) {
         $adapter->setMetadata($filename, ['contentType' => $fileMimeType]);
     }
     $adapter->write($filename, file_get_contents($file->getPathname()));
     if ($unlinkAfterUpload) {
         unlink($file->getPathname());
     }
     return $filename;
 }
開發者ID:intaro,項目名稱:file-uploader-bundle,代碼行數:26,代碼來源:FileUploader.php

示例8: getPhotoAction

 /**
  *
  * @param $photo_file
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  */
 public function getPhotoAction($photo_id)
 {
     if (!$this->getUser()) {
         return $this->redirectToRoute('fos_user_security_login');
     }
     $photo_file = $this->get('doctrine')->getRepository('IuchBundle:Photo')->findOneById($photo_id)->getNom();
     // Generate response
     $response = new Response();
     $filepath = $this->get('kernel')->getRootDir() . "/uploads/photos/" . $photo_file;
     $photoFile = new File($filepath);
     $response->headers->set('Cache-Control', 'private');
     $response->headers->set('Content-type', $photoFile->getMimeType());
     $response->headers->set('Content-Disposition', 'inline; filepath="' . $photoFile->getBasename() . '";');
     $response->headers->set('Content-length', $photoFile->getSize());
     // Send headers before outputting anything
     $response->sendHeaders();
     $response->setContent(file_get_contents($filepath));
     return $response;
 }
開發者ID:luciemannechez,項目名稱:projet-intranet_hopital,代碼行數:24,代碼來源:PhotoController.php

示例9: GetFile

 /**
  * @Route("/files/{fileName}")
  * @Method("GET")
  */
 public function GetFile($fileName)
 {
     $finder = new Finder();
     $finder->files()->name($fileName)->in('../data');
     if ($finder->count() == 0) {
         return new Response("File " . $fileName . " not found", 404);
     }
     $iterator = $finder->getIterator();
     $iterator->rewind();
     $file = $iterator->current();
     $oFile = new File(realpath($file));
     $response = new Response(null);
     $response->headers->set('Cache-Control', 'private');
     $response->headers->set('Content-type', $oFile->getMimeType());
     $response->headers->set('Content-Disposition', 'attachment; filename="' . $oFile->getBasename() . '";');
     $response->headers->set('Content-length', $oFile->getSize());
     $response->setContent(file_get_contents($oFile));
     return $response;
 }
開發者ID:vgratsilev,項目名稱:FileManageAPI,代碼行數:23,代碼來源:FilesController.php

示例10: PictureOrganismeAction

 public function PictureOrganismeAction($picture)
 {
     if (!$this->getUser()) {
         return $this->redirectToRoute('fos_user_security_login');
     }
     // Generate response
     $response = new Response();
     // Set headers
     $filepath = $this->get('kernel')->getRootDir() . "/uploads/organismes_pictures/" . $picture;
     $oFile = new File($filepath);
     $response->headers->set('Cache-Control', 'private');
     $response->headers->set('Content-type', $oFile->getMimeType());
     $response->headers->set('Content-Disposition', 'inline; filepath="' . $oFile->getBasename() . '";');
     $response->headers->set('Content-length', $oFile->getSize());
     // filename
     // Send headers before outputting anything
     $response->sendHeaders();
     $response->setContent(file_get_contents($filepath));
     return $response;
 }
開發者ID:WildCodeSchool,項目名稱:partnet,代碼行數:20,代碼來源:OrganismeController.php

示例11: setImporters

 /**
  * Inject the rootPath.
  *
  * @param File  $template
  * @param array $data
  */
 private function setImporters(File $template, User $owner)
 {
     foreach ($this->listImporters as $importer) {
         $importer->setRootPath($this->templateDirectory . DIRECTORY_SEPARATOR . $template->getBasename());
         $importer->setOwner($owner);
         $data = $this->container->get('claroline.manager.workspace_manager')->getTemplateData($template);
         $importer->setConfiguration($data);
         $importer->setListImporters($this->listImporters);
         if ($this->logger) {
             $importer->setLogger($this->logger);
         }
     }
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:19,代碼來源:TransferManager.php

示例12: removeTemplate

 public function removeTemplate(File $file)
 {
     $fileName = $file->getBasename();
     $extractPath = $this->templateDirectory . DIRECTORY_SEPARATOR . $fileName;
     $fs = new FileSystem();
     $fs->remove($extractPath);
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:7,代碼來源:WorkspaceManager.php

示例13: copyToRemote

 /**
  * @param File        $localFile
  * @param string      $remotePath
  * @param string|null $filename
  *
  * @return bool
  */
 private function copyToRemote(File $localFile, $remotePath, $filename = null)
 {
     $filename = $filename ? $filename : $localFile->getBasename();
     $success = $this->storage->put($remotePath . '/' . $filename, file_get_contents($localFile->getPathname()));
     return $success;
 }
開發者ID:stickableapp,項目名稱:stickable-api,代碼行數:13,代碼來源:ImageProcessor.php

示例14: transferFile

 public function transferFile()
 {
     //        dump($_POST['tf_file']);
     //        dump($_POST['from_connection']);
     //        dump($_POST['to_connection_name']);
     //        dump($_POST['to_path']);
     $proObj = new Provider($_POST['from_connection']);
     $filename = $proObj->downloadFile($_POST['tf_file'], 'temp');
     $proObj->deleteFile($_POST['tf_file']);
     $proObj = new Provider($_POST['to_connection_name']);
     $objfile = new File($filename);
     $file = array('name' => $objfile->getBasename(), 'type' => $objfile->getMimeType(), 'tmp_name' => $filename, 'error' => 0, 'size' => $objfile->getSize());
     $proObj->uploadFile($file, $_POST['to_path']);
     readfile($filename);
     unlink($filename);
 }
開發者ID:noxfate,項目名稱:gathercloud,代碼行數:16,代碼來源:HomeController.php

示例15: up

 /**
  * @param Schema $schema
  *
  * @throws SkipMigrationException
  */
 public function up(Schema $schema)
 {
     /*
      * Migration is not critical
      * Old format for storing image files to the new format
      *
      * Old format(date added image):
      *    media/{Y}/{m}/
      *
      * New Format(date added item):
      *    media/{Y}/{m}/{d}/{His}/
      */
     // move covers
     $items = $this->connection->fetchAll('
         SELECT
             `id`,
             `cover`,
             `date_add`
         FROM
             `item`
         WHERE
             `cover` IS NOT NULL AND
             `cover` != "" AND
             `cover`  NOT LIKE "example/%"');
     foreach ($items as $item) {
         $path = date('Y/m/d/His/', strtotime($item['date_add']));
         $file = new File($this->media_dir . $item['cover']);
         $file->move($this->media_dir . $path);
         $this->addSql('
             UPDATE
                 `item`
             SET
                 `cover` = ?
             WHERE
                 `id` = ?', [$path . $file->getBasename(), $item['id']]);
     }
     // move images
     $images = $this->connection->fetchAll('
         SELECT
             im.`id`,
             im.`source`,
             i.`date_add`
         FROM
             `item` AS `i`
         INNER JOIN
             `image` AS `im`
             ON
                 im.`item` = i.`id`');
     foreach ($images as $image) {
         $path = date('Y/m/d/His/', strtotime($image['date_add']));
         $file = new File($this->media_dir . $image['source']);
         $file->move($this->media_dir . $path);
         $this->addSql('
             UPDATE
                 `image`
             SET
                 `source` = ?
             WHERE
                 `id` = ?', [$path . $file->getBasename(), $image['id']]);
     }
     // skip if no data
     $this->skipIf(!($items && $images), 'No data to migrate');
 }
開發者ID:anime-db,項目名稱:catalog-bundle,代碼行數:68,代碼來源:Version20131015113854_ChangeImagePaths.php


注:本文中的Symfony\Component\HttpFoundation\File\File::getBasename方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。