为什么我无法上传到Laravel 5.1中的public_html?

时间:2016-05-18 17:40:14

标签: php laravel file-upload laravel-5.1 shared-hosting

我正在使用共享主机,我有2个文件夹。第一个'laravel'其他'public_html'。我想将照片上传到/ public_html / uploads / products /。但是当我上传照片时,我的照片会上传到laravel / public / uploads / products。如何从那里读取或如何上传到public_html

我的上传路径代码:

class UploadPaths
{
    public static $uploadPaths = array(
        'products_photos'     =>'/uploads/products_photos/'

    );
    public static function getUploadPath($path)
    {
        return public_path().self::$uploadPaths[$path];
    }
}

以下href代码:

<a href="{{"/../laravel/public/uploads/products_photos/".$product->photo}}" target="_blank" class="file-alert alert-info">{{$product->photo}}</a>

1 个答案:

答案 0 :(得分:1)

来自文档(https://laravel.com/docs/5.1/helpers):

public_path()

public_path函数返回公共目录的完全限定路径:

您的公共路径是项目中的Laravel公用文件夹。如果您需要其他文件夹,只需直接使用它,或保存在配置文件中。

请检查:https://laravel.com/docs/5.2/configuration

您可以获得:$public_path = config('public_path');

并在配置文件中设置:

<?php
return [
    // ...
    'public_path' => '/path/to/public/folder',
    // ...
];