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

转载于:https://www.cnblogs.com/shaoyikai/p/3968915.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值