官方网址: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