search

Use of WebUploader

Jun 05, 2018 am 09:24 AM
webuse

This article mainly introduces the use of WebUploader, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

var uploader = WebUploader.Uploader({     
    //几个常用的参数:swf,pick,formData,runtimeOrder  

    //所有参数列表  
    swf: 'path_of_swf/Uploader.swf',  
    dnd: '#dndArea', // [默认值:undefined] 指定Drag And Drop拖拽的容器,如果不指定,则不启动。  
    disableGlobalDnd: true,, // [默认值:false] 是否禁掉整个页面的拖拽功能,如果不禁用,图片拖进来的时候会默认被浏览器打开  
    paste: '#uploader', // [默认值:undefined] 指定监听paste事件的容器,如果不指定,不启用此功能。此功能为通过粘贴来添加截屏的图片。建议设置为document.body.  
    pick:'#filePicker',//也可以用下面的方式详细配置  
    // {Selector, Object}  [默认值:undefined] 指定选择文件的按钮容器,不指定则不创建按钮。  
    pick: {  
        id: '#filePicker',//Seletor|dom 指定选择文件的按钮容器,不指定则不创建按钮。注意 这里虽然写的是 id, 但是不是只支持 id, 还支持 class, 或者 dom 节点。  
        label: '点击选择图片',//请采用 innerHTML 代替  
        innerHTML: "点击选择图片",// 指定按钮文字。不指定时优先从指定的容器中看是否自带文字。  
        multiple:true //是否开起同时选择多个文件能力。  
    },  
    //限制上传的文件类型  
    accept: {  
        title: 'Images',// {String} 文字描述  
        extensions: 'gif,jpg,jpeg,bmp,png,rar',// {String} 允许的文件后缀,不带点,多个用逗号分割。  
        mimeTypes: 'image/gif,image/jpg,image/jpeg,image/bmp,image/png,.rar'// 多个用逗号分割。  
    },  
    // 设置缩略图。  
    thumb: {  
        width: 110,  
        height: 110,  
        // 图片质量,只有type为`image/jpeg`的时候才有效。  
        quality: 70,  
        // 是否允许放大,如果想要生成小图的时候不失真,此选项应该设置为false.  
        allowMagnify: true,  
        // 是否允许裁剪。是否采用裁剪模式。如果采用这样可以避免空白内容。  
        crop: true,  
        // 为空的话则保留原有图片格式。  
        // 否则强制转换成指定的类型。  
        type: 'image/jpeg'  
    },  
    // 配置压缩的图片的选项。如果此选项为false, 则图片在上传前不进行压缩。  
    compress: {  
        width: 1600,  
        height: 1600,  
        // 图片质量,只有type为`image/jpeg`的时候才有效。  
        quality: 90,  
        // 是否允许放大,如果想要生成小图的时候不失真,此选项应该设置为false.  
        allowMagnify: false,  
        // 是否允许裁剪。  
        crop: false,  
        // 是否保留头部meta信息。  
        preserveHeaders: true,  
        // 如果发现压缩后文件大小比原来还大,则使用原来图片  
        // 此属性可能会影响图片自动纠正功能  
        noCompressIfLarger: false,  
        // 单位字节,如果图片大小小于此值,不会采用压缩。  
        compressSize: 0  
    },   


    auto: true, // [默认值:false] 设置为 true 后,不需要手动调用上传,有文件选择即开始上传。  
    runtimeOrder: 'flash', // [默认值:html5,flash] 指定运行时启动顺序。默认会想尝试 html5 是否支持,如果支持则使用 html5, 否则则使用 flash.可以将此值设置成 flash,来强制使用 flash 运行时。  
    prepareNextFile:false, // [默认值:false] 是否允许在文件传输时提前把下一个文件准备好。 对于一个文件的准备工作比较耗时,比如图片压缩,md5序列化。 如果能提前在当前文件传输期处理,可以节省总体耗时。  
    chunked:false, // [默认值:false] 是否要分片处理大文件上传。  
    chunkSize: 512 * 1024,// [默认值:5242880] 如果要分片,分多大一片? 默认大小为5M.  
    chunkRetry:2, // [默认值:2] 如果某个分片由于网络问题出错,允许自动重传多少次?  
    threads:3, // [默认值:3] 上传并发数。允许同时最大上传进程数。  
    formData: {"test":"123123","shui":"ping"}, // [默认值:{}] 文件上传请求的参数表,每次发送都会发送此对象中的参数。  
    fileVal:"pictures", // [默认值:'file'] 设置文件上传域的name。  
    method :"POST", // [默认值:'POST'] 文件上传方式,POST或者GET。  
    sendAsBinary :false, // [默认值:false] 是否已二进制的流的方式发送文件,这样整个上传内容php://input都为文件内容, 其他参数在$_GET数组中。  
    fileNumLimit :10, // [默认值:undefined] 验证文件总数量, 超出则不允许加入队列。  
    fileSizeLimit : 200 * 1024 * 1024,    // 200 M  [默认值:undefined] 验证文件总大小是否超出限制, 超出则不允许加入队列。  
    fileSingleSizeLimit: 50 * 1024 * 1024,    // 50 M [默认值:undefined] 验证单个文件大小是否超出限制, 超出则不允许加入队列。  
    duplicate :true, // [默认值:undefined] 去重, 根据文件名字、文件大小和最后修改时间来生成hash Key.  
    disableWidgets: {String, Array}, // [默认值:undefined] 默认所有 Uploader.register 了的 widget 都会被加载,如果禁用某一部分,请通过此 option 指定黑名单。  });

The back-end php uses the laravel framework, which is very convenient :

public function uploadFile(Request $request){
    set_time_limit(100);    // dd(request()->all());
    $type = request('type', 0);    
    if ($type == 1) {
            $rules = [            'document' => 'sometimes|required|file|mimes:word,ppt,pdf,jpg,png,jpeg|max:10240',
        ];
    } else {        
            $rules = [            'file' => 'required|image|max:2048',
        ];
    }    
    $validator = Validator::make($request->all(), $rules);    
    if ($validator->fails())
     {        
      $error_message = $validator->errors()->all();        
      return $type == 1 ? false : $this->outPutJson('', 501, $error_message);
    }
        $file = $type == 1 ? $request->file('document') : $request->file('file');    
        $save_path = 'courseware';    
        $mime_type = $file->getClientOriginalExtension();    //保存文件
    $save_name = date('Ymd_H_i_s_') . uniqid() . '.' . $mime_type;    
    $path = $file->storeAs($save_path, $save_name, 'ftp');    
    return $type == 1 ? $path : $this->outPutJson($path);
}

The above is the detailed content of Use of WebUploader. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.