PHP ftp_put()上传文件非常慢这里是我的代码

时间:2016-05-07 06:10:53

标签: php jwplayer

我正在尝试在我的服务器上传视频,然后在jwplayer帐户中添加视频网址。在服务器上传视频之前,此代码工作正常。但现在提交表单需要花费太多时间。实际问题是ftp_put功能。这个功能可以在几秒钟内轻松上传文件或视频,但不能快速提交。这需要5到10分钟。

    //allowable file extension define here.
$jwplayer_source_format_extensions = [
    'aac' => ['aac', 'm4a', 'f4a'],
    'flv' => ['flv'],
    'm3u8' => ['m3u', 'm3u8'],
    'mp3' => ['mp3'],
    'mp4' => ['mp4', 'm4v', 'f4v', 'mov'],
    'rtmp' => ['rtmp', 'rtmpt', 'rtmpe', 'rtmpte'],
    'smil' => ['smil'],
    'vorbis' => ['ogg', 'oga'],
    'webm' => ['webm'],
];

    if(!empty ($_FILES['video_file']['name'])){ 
        //assign $url variable filename.        
        $url = $_FILES['video_file']['name'];
        //get file extension and assign to $extension Variable
        $extension = pathinfo( $url, PATHINFO_EXTENSION );
        //set default file extension
        $sourceformat = 'mp4';
        //check file extension if not found $jwplayer_source_format_extensions in array script will break
        foreach ($jwplayer_source_format_extensions  as $format => $extensions ) {
            if (in_array( $extension, $extensions, true ) ) {
                $sourceformat = $format;
                break;
            }
        }
        //assign file name to $source_file variable.ftp_put Use this Variable.
        $source_file = $_FILES['video_file']['tmp_name']; 
        //$destination_file = '/cgi-bin/testingvideo/'; 
        // set up basic connection 
        $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 
        // login with username and password 
        $login_result = ftp_login($conn_id, $ftpuser, $ftppass); 
        //upload the file 
            //ftp_chdir($conn_id, $destination_file);   
        $upload = ftp_put($conn_id, $_FILES['video_file']['name'], $source_file, FTP_BINARY); // the ftp function 
        //check upload status 
        if (!$upload) {
            echo 'video not Upload';
            die;
        }
        // close the connection 
        ftp_close($conn_id); 

        $surl = 'http://'.$ftp_server.'/'.$url;

        $params = [
            'sourcetype' => 'url',
            'sourceurl' => $surl,
            'sourceformat' => $sourceformat,
        ];

    if(!empty ($post['title'])){ $params['title'] = $post['title']; }
    if(!empty ($post['tags'])) { $params['tags'] = $post['tags']; }
    else{ $params['tags'] = ''; }

    $botr_api->call('/videos/create',$params);  
        header('Location: video_list.php');
        exit;   
    }

0 个答案:

没有答案