ftp配置 Laravel上传文件到ftp服务器

listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
use_localtime=YES
xferlog_file=/var/log/vsftpd.log
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=ftp
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO
utf8_filesystem=YES

use_localtime=YES
connect_timeout=60
accept_timeout=60
max_clients=8
max_per_ip=8

#主动模式
port_enable=YES
connect_from_port_20=NO
ftp_data_port=21
pasv_promiscuous=YES
#被动模式
#pasv_enable=YES
#pasv_min_port=30000
#pasv_max_port=30001

用主动模式的时候,laravel默认就可以上传文件了。
D:phpStudyWWWxxxconfigfilesystems.php

'ftp' => [
    'driver' => 'ftp',
    'host' => '52.xx.xx.239',
    'username' => 'xx',
    'password' => 'xx',
    'root' => '/xx/xx/data',
    'passive' => false,
    'timeout' => 100,
],

上传文件代码:

public function multiUpload($imageArray, $path = '', $prefix = '')
{
    set_time_limit(800);
    if (!$imageArray || count($imageArray) > 50) {
        return false;
    }
    $new_image_array = [];
    foreach ($imageArray as $key => $value) {
        $mime_type = $value->getClientOriginalExtension();
        $save_name = $prefix . str_random(6) . '.' . $mime_type;
        // $new_image_array['image'][] = $value->storeAs($path, $save_name, 'ftp');
        $new_image_array['image'][] = 'storage/' . $value->storeAs($path . '/image', $save_name, 'public');
    }
    return $new_image_array;
}

或者下面的 形式ftp存文件

        //测试ftp上传
        Storage::disk('ftp')->put('data/1.txt', "ftp123456222");
        $exists = Storage::disk('ftp')->exists('data/12.txt');
        var_dump($exists);

 或下面这个 上传也挺好的

if(!empty($request->file())){            //判断是否有文件传入
            $file = $request->file($fileName);                //获取到请求文件
            if(!empty($file)){            //判断文件是否存在
                $fileExt = $file->getClientOriginalExtension();        //获取文件后缀名
                $realPath = $file->getRealPath();        //获取文件真实路径
                $filename = date('YmdHis') . uniqid() . '.' . $fileExt;        //按照一定格式取名
                $filepath = $fileName.'/';        //个人要求的路径
                $bool = Storage::disk('ftp')->put('/data/'.$filepath.$filename, file_get_contents($realPath));            //使用Storage传文件至ftp
                $fileServer = $server;        //ftp的ip地址
                $fileUrl = $fileServer.$filepath.$filename;        //文件的url地址
                if($bool){
                    return $fileUrl;        //返回文件url,可用于传入数据库
                } else{
                    return '500';
                }
            }
        }
        return null;
    }

转 :  https://blog.csdn.net/zhezhebie/article/details/80679764

Laravel移动本地文件到ftp服务器

从本地移动文件到远程服务器: (laravel 5.7 才支持这个功能)

Storage::disk('ftp')
  ->writeStream(
    'remote-file.zip',
    Storage::disk('local')->readStream('local-file.zip')
  );

To response-streams:

return response()->stream( function() {
    fpassthru( Storage::disk('s3')->readStream('file.zip') );
  });

转 : https://blog.csdn.net/zhezhebie/article/details/85763217

原文地址:https://www.cnblogs.com/fps2tao/p/11347356.html