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:\phpStudy\WWW\xxx\config\filesystems.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;
}

猜你喜欢

转载自blog.csdn.net/zhezhebie/article/details/80679764