如何在上传中添加进度条(PHP)

时间:2017-12-14 11:26:48

标签: php wordpress upload progress-bar

如何在我的上传页面上添加进度条?
我将使用Wordpress模板来集成上传器。

这是我现在拥有的上传代码:

global $post;
/*Video Uploading*/

if ( isset($_FILES['upload_attachment']) ) {
    $count = '0';
    $files = $_FILES['upload_attachment'];

    foreach ($files['name'] as $key => $value) {
        if ($files['name'][$key]) {
            $file = array(
                'name'     => $files['name'][$key],
                'type'     => $files['type'][$key],
                'tmp_name' => $files['tmp_name'][$key],
                'error'    => $files['error'][$key],
                'size'     => $files['size'][$key]
            );

            $_FILES = array("upload_attachment" => $file);

            foreach ($_FILES as $file => $array) {
                $newupload = betube_insert_attachment($file,$post->ID);
                $attachvideo = wp_get_attachment_url( $newupload);
                add_post_meta($post_id, 'jtheme_video_file', $attachvideo);
                add_post_meta($post_id, '_video_thumbnail', $newupload);
                set_post_thumbnail( $post_id, $newupload );
                $count++;
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

要添加进度条,您必须使用jquery / ajax上传文件。有一个名为'progress'的默认javascript事件监听器,用于递增进度条。这是一个完整的工作示例,但请确保您在wordpress中工作,因此ajax php代码将根据您的要求进行更改。演示: http://theonlytutorials.com/jquery-ajax-file-upload-with-percentage-progress-bar/