【问题标题】:Laravel uploading a file to the right directoryLaravel将文件上传到正确的目录
【发布时间】:2014-04-21 15:52:15
【问题描述】:

我上传文件好了。只是事实证明,在我的例子中,起始目录是公共的,这导致当文件应该位于受先前身份验证保护的目录中时,每个人都可以访问这些文件,即在 App 下。

所以,当我这样做时:

$file = Input::file('fichero');
$destinationPath = 'uploads/folder';
$file->move($destinationPath);

// Create model
$model = new Model;
$model->filename = $file->getClientOriginalName();
$model->destinationPath = $destinationPath;

文件保存在这里:localh.../myweb/public/

这在我所有应用程序文件所在的 App 父文件夹之外。

我可以想象去那个目录的事实是因为它在配置文件中采用了默认值,即 localhost/laravel/public/index.php/

所以,写类似的东西

$file->move(base_path().'/uploadfolder/subdirectory/', $newname);

将从固定为 base_path 的内容开始,但 base_path 需要类似于 localhost/mywebname/public。

那么,如何编写路径以使其进入 App 下的目录而不是 Public 下的目录?

我希望我不是在问一个愚蠢的问题,但我已经尝试了好几天,我已经阅读了这里的 3 个相关查询。

谢谢

【问题讨论】:

    标签: laravel upload


    【解决方案1】:

    您可以使用:

    app_path() // Path to the 'app' folder
    app_path('controllers/admin') // Path to the 'app/controllers/admin' folder
    

    这将返回您的本地文件系统路径,您应该将上传的图片放在public/... 文件夹中。

    【讨论】:

    • 非常感谢!最好的问候
    猜你喜欢
    • 2016-11-18
    • 1970-01-01
    • 2014-10-08
    • 2019-12-01
    • 2017-06-29
    • 1970-01-01
    • 2019-10-15
    • 2013-04-09
    • 1970-01-01
    相关资源
    最近更新 更多