1. 程式人生 > >ftp配置 Laravel上傳檔案到ftp伺服器

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;
}