/** * 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; }
/** * @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); }
/** * 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); } }
/** * @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(); } }
/** * 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); }
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; }
/** * 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; }
/** * * @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; }
/** * @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; }
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; }
/** * 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); } } }
public function removeTemplate(File $file) { $fileName = $file->getBasename(); $extractPath = $this->templateDirectory . DIRECTORY_SEPARATOR . $fileName; $fs = new FileSystem(); $fs->remove($extractPath); }
/** * @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; }
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); }
/** * @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'); }