示例#1
0
 /**
  * Copies the given file to a new location.
  *
  * @param \Aimeos\MW\Media\Image\Iface $mediaFile Media object
  * @param unknown_type $domain Domain the image belongs to, e.g. "product", "attribute", etc.
  * @param string $filename Name of the new file without file extension
  * @throws \Aimeos\Controller\ExtJS\Exception If the configuration is invalid or due to insufficient permissions
  */
 protected function copyFile(\Aimeos\MW\Media\Iface $mediaFile, $domain, $filename)
 {
     $config = $this->getContext()->getConfig();
     if (($mediadir = $config->get('controller/extjs/media/standard/upload/directory', null)) === null) {
         throw new \Aimeos\Controller\ExtJS\Exception('No media directory configured');
     }
     $ds = DIRECTORY_SEPARATOR;
     $fileext = $this->getFileExtension($mediaFile->getMimetype());
     $filepath = $mediadir . $ds . 'files' . $ds . $domain . $ds . $filename[0] . $ds . $filename[1];
     $dest = $this->getAbsoluteDirectory($filepath) . $ds . $filename . $fileext;
     $mediaFile->save($dest, $mediaFile->getMimetype());
     $perms = $config->get('controller/extjs/media/standard/upload/fileperms', 0664);
     if (chmod($dest, $perms) === false) {
         $msg = sprintf('Changing file permissions for "%1$s" to "%2$o" failed', $dest, $perms);
         $this->getContext()->getLogger()->log($msg, \Aimeos\MW\Logger\Base::WARN);
     }
     return "{$mediadir}/files/{$domain}/{$filename[0]}/{$filename[1]}/{$filename}{$fileext}";
 }
示例#2
0
 /**
  * Stores a binary file and returns it's new relative file name
  *
  * @param \Aimeos\MW\Media\Iface $mediaFile Media object
  * @param string $type Type of the image like "preview" or "files"
  * @param string $filename Name of the new file without file extension
  * @param string Name of the file system to store the files at
  * @return string Relative path to the new file
  * @throws \Aimeos\Controller\Common\Exception If an error occurs
  */
 protected function storeFile(\Aimeos\MW\Media\Iface $mediaFile, $type, $filename, $fsname)
 {
     $file = $mediaFile->getFilepath();
     $fileext = $this->getFileExtension($mediaFile->getMimetype());
     $dest = "{$type}/{$filename[0]}/{$filename[1]}/{$filename}{$fileext}";
     $this->context->getFilesystemManager()->get($fsname)->writef($dest, $file);
     return $dest;
 }