zoukankan      html  css  js  c++  java
  • uploadify 一款优秀的上传插件

    官方网址:www.uploadify.com

    使用文档:www.uploadify.com/documentation

    效果如下

    注释以及文件结构已经过本人修改,和官方的有些出入。

    index.php

    <!DOCTYPE HTML>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Uploadiy 测试</title>
        <script src="./js/jquery.min.js" type="text/javascript"></script>
        <script src="./js/jquery.uploadify.min.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="./css/uploadify.css">
        <style type="text/css"> body {font: 13px Arial, Helvetica, Sans-serif;} </style>
    </head>
    
    <body>
        <h1>Uploadify 演示</h1>
        <form>
            <div id="queue"></div>
            <input id="file_upload" name="file_upload" type="file" multiple="true">
        </form>
    
        <script type="text/javascript">
            <?php $timestamp = time();?>
            $(function() {
                $('#file_upload').uploadify({
    
                    // 'width'    : 300 // 调节上传按钮的宽度(像素)
                    // 'height'    :28,    // 调节上传按钮的高度(像素)
                    // 'buttonImage':'img/select_file.png', // 选择按钮
                    // 'requeueErrors' : true, 
                    // 'uploadLimit' : 1, // 限制文件上传数量
                    // 'fileSizeLimit' : '100KB',
                    // 'fileTypeExts' : '*.gif; *.jpg; *.png',
                    // 'formData'      : {'someKey' : 'someValue', 'someOtherKey' : 1},
                    // 'method'   : 'post', // 或者 'get'
                    // 'debug'    : true, // 调试使用
                    // 'multi'    : false, // 是否多文件上传
    
                    'formData'     : {
                        'timestamp' : '<?php echo $timestamp;?>',
                        'token'     : '<?php echo md5('unique_salt' . $timestamp);?>'
                    },
                    'swf'      : 'uploadify.swf',
                    'uploader' : 'uploadify.php',    // 处理上传文件的php脚本地址
                });
            });
        </script>
    </body>
    </html>

    uploadify.php

    <?php
    /*
    Uploadify
    Copyright (c) 2012 Reactive Apps, Ronnie Garcia
    Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
    */
    
    // 文件存放路径
    $targetFolder = '/uploadify/uploads'; // 相对于根目录
    
    $verifyToken = md5('unique_salt' . $_POST['timestamp']);
    
    if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
        $tempFile = $_FILES['Filedata']['tmp_name'];
        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
        $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
        
        // 验证文件类型
        $fileTypes = array('jpg','jpeg','gif','png'); // 文件扩展名
        $fileParts = pathinfo($_FILES['Filedata']['name']);
        
        if (in_array($fileParts['extension'],$fileTypes)) {
            // file_put_contents('log.txt', $targetFile); // 可以据此输出log,查看上传文件信息
            move_uploaded_file($tempFile,$targetFile);
            echo '1';
        } else {
            echo 'Invalid file type.';
        }
    }
    ?>

    源代码下载:uploadify.zip

  • 相关阅读:
    Oracle数据库安装
    [转]卡西欧手表调日期正确方法
    python密码处理(可用于生产模式)
    [转]python对json的相关操作
    [转]Python中的with…as…
    Python标准库--os模块
    我的github代码添加
    Python正则表达式+自创口诀
    自己总结python用xlrdxlwt读写excel
    CentOS安装+配置+远程
  • 原文地址:https://www.cnblogs.com/shaoyikai/p/3968915.html
Copyright © 2011-2022 走看看