本文整理汇总了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;
}
示例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);
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例12: removeTemplate
public function removeTemplate(File $file)
{
$fileName = $file->getBasename();
$extractPath = $this->templateDirectory . DIRECTORY_SEPARATOR . $fileName;
$fs = new FileSystem();
$fs->remove($extractPath);
}
示例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;
}
示例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);
}
示例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');
}