Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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 如何在公共html中保存图像,而不是在laravel中保存默认存储?_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 如何在公共html中保存图像,而不是在laravel中保存默认存储?

Php 如何在公共html中保存图像,而不是在laravel中保存默认存储?,php,laravel,laravel-5,Php,Laravel,Laravel 5,Laravel共享主机保存图像问题: 情况: 无法创建symlink()“为安全起见,已禁用symlink() 原因“ 不支持ssh,只支持ftp 如何将图像保存到public\u html让我们说一个文件storage/cover\u image 这是开发过程中生成的快捷方式 我在my\u upload中制作了一个名为“我的上传”的自定义磁盘,我不知道它保存文件的位置,但它不保存在public\u html/storage/cover\u images中 //custom my_disk

Laravel共享主机保存图像问题:

情况:

  • 无法创建symlink()
    “为安全起见,已禁用symlink()
    原因“
  • 不支持ssh,只支持ftp
如何将图像保存到
public\u html
让我们说一个文件
storage/cover\u image

这是开发过程中生成的快捷方式

我在
my\u upload
中制作了一个名为“我的上传”的自定义磁盘,我不知道它保存文件的位置,但它不保存在
public\u html/storage/cover\u images中

//custom my_disk code
'my_upload' => [
        'driver' => 'local',
        'root' => public_path().'/storage/cover_images',
        'visibility' => 'public',
    ],

如果我使用Store,因为它总是存储
存储
而不是
公共html
中的,这也不是权限问题,因为我还在测试,我已经将权限设置为
777

看起来你在共享主机上,据我所知,大多数主机提供商对php.ini配置cmiiw都有自己的规则

因此,如果您想将图像放在public_html上,可以这样做:

$path = '/home/{your_shared_hosting_username}/public_html/cover_image';
$request->file('cover_image')->move($path, $filename);

看起来您使用的是共享主机,据我所知,大多数主机提供商对php.ini配置cmiiw都有自己的规则

因此,如果您想将图像放在public_html上,可以这样做:

$path = '/home/{your_shared_hosting_username}/public_html/cover_image';
$request->file('cover_image')->move($path, $filename);

经过数小时的研究和磨砺终于解决了我的问题。。。去帮助别人

第1步:

config/filesystem.php

//In my case
'my_upload' => [
        'driver' => 'local',
        'root' => public_path().'/storage',
        'visibility' => 'public',
    ],

第二步:

public\u path()
更改为
public\u html

//What worked for me 
//Changed file: public_html/index.php 
//after bootstrap declaration-> this is important

$app->bind('path.public', function() {
    return __DIR__;
});
第三步:

现在像这样保存文件

// Handle File Upload
       if($request->hasFile('cover_image')){
           // Get filename with the extension
           $filenameWithExt = $request->file('cover_image')->getClientOriginalName();
           // Get just filename
           $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
           // Get just ext
           $extension = $request->file('cover_image')->getClientOriginalExtension();
           // Filename to store
           $fileNameToStore= $filename.'_'.time().'.'.$extension;
           // Upload Image
          $path = $request->file('cover_image')->storeAs('cover_images', $fileNameToStore,['disk' => 'my_upload']);
       if(!$path){
               return false;

               }

       } else {
           $fileNameToStore = 'noimage.jpg';
       }
在我的情况下,我的图像将保存在
public\u html/storage/cover\u images

//custom my_disk code
'my_upload' => [
        'driver' => 'local',
        'root' => public_path().'/storage/cover_images',
        'visibility' => 'public',
    ],
资源:

但是,这并没有减少它,因为图像存储在laravel
public
中,所以您必须将默认的laravel public更改为您现在的
public\u html
,这是您在共享主机中的公共内容

在laravel 5.8上测试

NB:我还注意到运行laravel
config:cache
会破坏保存位置。您可能应该避免使用此命令


如果您已经运行了命令
config:clear
undo's

,经过数小时的研究和磨砺,最终解决了我的问题。。。去帮助别人

第1步:

config/filesystem.php

//In my case
'my_upload' => [
        'driver' => 'local',
        'root' => public_path().'/storage',
        'visibility' => 'public',
    ],

第二步:

public\u path()
更改为
public\u html

//What worked for me 
//Changed file: public_html/index.php 
//after bootstrap declaration-> this is important

$app->bind('path.public', function() {
    return __DIR__;
});
第三步:

现在像这样保存文件

// Handle File Upload
       if($request->hasFile('cover_image')){
           // Get filename with the extension
           $filenameWithExt = $request->file('cover_image')->getClientOriginalName();
           // Get just filename
           $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
           // Get just ext
           $extension = $request->file('cover_image')->getClientOriginalExtension();
           // Filename to store
           $fileNameToStore= $filename.'_'.time().'.'.$extension;
           // Upload Image
          $path = $request->file('cover_image')->storeAs('cover_images', $fileNameToStore,['disk' => 'my_upload']);
       if(!$path){
               return false;

               }

       } else {
           $fileNameToStore = 'noimage.jpg';
       }
在我的情况下,我的图像将保存在
public\u html/storage/cover\u images

//custom my_disk code
'my_upload' => [
        'driver' => 'local',
        'root' => public_path().'/storage/cover_images',
        'visibility' => 'public',
    ],
资源:

但是,这并没有减少它,因为图像存储在laravel
public
中,所以您必须将默认的laravel public更改为您现在的
public\u html
,这是您在共享主机中的公共内容

在laravel 5.8上测试

NB:我还注意到运行laravel
config:cache
会破坏保存位置。您可能应该避免使用此命令


如果您已经运行了命令
config:clear
undo的

,只需一个简短提示。不要像你现在使用的那样使用主机提供商,只要通过像digitalocean这样的人租一个VPS,并拥有完全的控制权现在我知道你更喜欢共享主机吗?是的,这是一个共享主机只是一个小提示。不要像你现在使用的那样使用主机提供商,只要通过像digitalocean这样的人租一个VPS,并拥有完全的控制权现在我知道你更喜欢共享主机吗?是的,这是一个共享主机