在 burzum/cakephp-file-storage 插件中更改保存文件夹

Change save folder in burzum/cakephp-file-storage plugin

我正在使用插件在 Cake 中保存文件PHP 3: burzum/cakephp-file-storage, 一切都很完美 但现在我需要更改动态保存文件的目录(通过目录 例如,文件由参数保存),我该怎么做?

实际路径:

[htdocs]\[AppName]\tmp[FileExtension.png]

它可能停留在下面的结构例如:

[htdocs]\[AppName-Images]\Products[FileExtension.png]

PHP代码:

public function saveFileLFS($stringSeparator, $storeName, $productName) 
{ 
  $key = $storeName . $stringSeparator . $productName . $stringSeparator . 
  $this->request->data['Media']['file']['name']; 
  if(StorageManager::adapter('Local')->write($key, 
     file_get_contents($this->request->data['Media']['file']['tmp_name']))){ 
  return true; 
}else 
{ 
  return false; 
} 
} 

Github Link

它以 TMP 结束的原因是这是插件附带的 默认 配置。它转到 TMP 因为这是除了日志之外唯一应该在适当的应用程序设置中可写的地方,并且插件应该开箱即用。也许我会在未来的版本 (4.0) 中更改它,以便您必须配置它才能使用它,让人们知道它。

对于本地适配器,将其更改为:

StorageManager::config('Local', [
    'adapterOptions' => [ROOT . DS . 'file_storage' . DS], // Your base path here
    'adapterClass' => '\Gaufrette\Adapter\Local',
    'class' => '\Gaufrette\Filesystem'
]);

这将覆盖默认值。 Actually this is already documented and explained here.

我建议你看看1.1.0 branch (currently release is 1.1.0-RC1). Some people already use it and I'm happy to get feedback about it. The whole way paths and file names are generated has been completely rewritten and abstracted into a set of classes called "path builders"。