【问题标题】:How to get path of uploaded image in Octobercms backend?如何在 Octobercms 后端获取上传图片的路径?
【发布时间】:2017-02-11 04:56:18
【问题描述】:

我在使用 octoberCMS 在后端上传图片时遇到问题。 图片实际上是上传的,但我需要将图片路径与我的模型一起保存。我无法获得完整的路径,我最多只能获得:

/storage/app/uploads/public//

请问如何获取上传图片的完整路径?

【问题讨论】:

    标签: octobercms


    【解决方案1】:

    如果您想使用媒体查找器上传器对象从媒体管理器部分获取路径;您可以使用此代码。

    Config::get('cms.storage.media.path')
    

    【讨论】:

      【解决方案2】:

      为您的模型添加功能:

      public function getAll(){
          return self::get();
      }
      

      在页面中添加 onInit() 函数后:

      function onInit() {
          $model = new Author\PluginName\Models\ClassName(); // change path to your model
          $this['alldata']= $model->getAll();
      
      }
      

      之后,您将在页面上获得所有带有图像的数据。 您可以通过这种方式获取图像路径:

      {% for item in alldata %}
      
         {{ item.fileupload1.path}} // change 'fileupload1' to your file input name   
      
      {% endfor %}
      

      【讨论】:

      • 一切正常,但我认为 item.fileupload1.path 不正确,应该是 item.fileupload1.getPath()
      猜你喜欢
      • 1970-01-01
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 2016-08-16
      相关资源
      最近更新 更多