Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel文件上载在godaddy服务器中不工作_Php_Laravel_File Upload - Fatal编程技术网

Php Laravel文件上载在godaddy服务器中不工作

Php Laravel文件上载在godaddy服务器中不工作,php,laravel,file-upload,Php,Laravel,File Upload,在我的laravel项目中上载文件时遇到问题。它在本地工作正常,但在godaddy服务器上不工作。我使用以下方法存储我的文件 第一种方法: $image = $request->file('avatar_file'); $imageName = time().'.'.request()->avatar_file>getClientOriginalExtension(); $destinationPath = public_path().'/images/' ; request(

在我的
laravel
项目中上载文件时遇到问题。它在本地工作正常,但在
godaddy
服务器上不工作。我使用以下方法存储我的文件

第一种方法:

$image = $request->file('avatar_file');
$imageName = time().'.'.request()->avatar_file>getClientOriginalExtension();
$destinationPath = public_path().'/images/' ;
request()->avatar_file->move($destinationPath, $imageName);
第二种方法:

$image = $request->file('file');
$imageName = time().'.'.request()->file->getClientOriginalExtension();
$request->file('file')->storeAs('documents', $imageName);

我已为此在本地而非服务器上工作创建了符号链接。

由于您在共享托管平台上托管了Laravel应用程序,您的应用程序不知道到公用目录的正确路径

因此,您需要在
public/index.php
文件中定义如下函数:(将其粘贴在
index.php
文件的顶部)

在此处定义此函数会导致跳过同名的helper函数,从而允许重写其功能。这是为Laravel的“公共”目录使用“非标准”位置所必需的

现在为您的路径创建一个新的服务提供商:
php artisan make:PublicPathServiceProvider

register()
函数中,您需要以下代码:

public function register()
    {
        if (env('PUBLIC_PATH') !== null) {
            //An example that demonstrates setting Laravel's public path.
            $this->app['path.public'] = base_path().'/../'.env('PUBLIC_PATH');
        } else {
            $this->app['path.public'] = base_path().'/../public_html';
        }

        // Possible environment changes
        if ($this->app->environment() === 'local') {
        } elseif ($this->app->environment() === 'test') {
        } elseif ($this->app->environment() === 'production') {
        }
    }
现在,在您的应用程序中注册此提供商。
config/app.php

在“提供程序”下添加以下内容:

App\Providers\PublicPathServiceProvider::class,

最后一步,在
.env
文件中,创建一个新变量:
PUBLIC\u PATH=/PUBLIC\u html

你可以走了

注意:不要忘记检查您上传Laravel应用程序的路径。(以上假设路径为public_html)

重要提示:更改配置后,可能需要清除缓存:

php-artisan-config:cache

php artisan缓存:清除

public function register()
    {
        if (env('PUBLIC_PATH') !== null) {
            //An example that demonstrates setting Laravel's public path.
            $this->app['path.public'] = base_path().'/../'.env('PUBLIC_PATH');
        } else {
            $this->app['path.public'] = base_path().'/../public_html';
        }

        // Possible environment changes
        if ($this->app->environment() === 'local') {
        } elseif ($this->app->environment() === 'test') {
        } elseif ($this->app->environment() === 'production') {
        }
    }