jquery uploadify修改上传的文件名和显示
2013-12-21 11:35
423 查看
如果觉得看文章太麻烦,可以直接看参考:http://stackoverflow.com/questions/7707687/jquery-uploadify-change-file-name-as-it-is-being-uploaded
贴上jquery uploadify官网地址:http://www.uploadify.com/
哎呀,纠结了一上午,我说怎么file.name怎么都是我上传的名字,后来一查,我的天,原来是这个,data,我一直用的是file.name来显示的,才发现是用data来获取新的文件名称
我用的是thinkphp,所以修改的文件,麻烦哟,我的uploadify的文件路径是放在admin/Tpl/Index/uploadify这个路径下的,所以我的文件就变成了
uploadify.php
页面调用方法:
参数说明:
贴上jquery uploadify官网地址:http://www.uploadify.com/
哎呀,纠结了一上午,我说怎么file.name怎么都是我上传的名字,后来一查,我的天,原来是这个,data,我一直用的是file.name来显示的,才发现是用data来获取新的文件名称
'onUploadSuccess' : function(file, data, response) { alert('Renamed file name is - ' + data); }
我用的是thinkphp,所以修改的文件,麻烦哟,我的uploadify的文件路径是放在admin/Tpl/Index/uploadify这个路径下的,所以我的文件就变成了
uploadify.php
<?php /* Uploadify Copyright (c) 2012 Reactive Apps, Ronnie Garcia Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> */ // Define a destination //$targetFolder = 'stStone/Tpl/images/'; // Relative to the root $verifyToken = md5('unique_salt' . $_POST['timestamp']); if (!empty($_FILES) && $_POST['token'] == $verifyToken) { $tempFile = $_FILES['Filedata']['tmp_name']; //由于是要前台显示,所以用了很多个dirname() $targetPath = dirname(dirname(dirname(dirname(dirname(__FILE__))))).'/Tpl/Index/images/'; //获取文件的一些信息 $fileParts = pathinfo($_FILES['Filedata']['name']); //图片名称规则是 当前时间的时分秒.类型 如:20131221030820.jpg $filenames = date("YmdHis").".".$fileParts['extension']; //图片的完整路径咯 $targetFile = rtrim($targetPath,'/') . '/' .$filenames; // Validate the file type $fileTypes = array('jpg','jpeg','gif','png'); // File extensions if (in_array($fileParts['extension'],$fileTypes)) { if(!file_exists($targetFile)){ move_uploaded_file($tempFile,$targetFile); chmod($targetFile,0777); }else{ unlink($targetFile); move_uploaded_file($tempFile,$targetFile); chmod($targetFile,0777); } //必须得返回这个图片名称哦 echo $filenames; } else { echo 'Invalid file type.'; } } ?>
页面调用方法:
<?php $timestamp = strtotime(date("YmdHis")); ?> jQuery('#scroll_upload').uploadify({ 'multi':false, 'formData' : { 'timestamp' : '<?php echo $timestamp;?>', 'token' : '<?php echo md5('unique_salt' . $timestamp);?>' }, 'swf':'<?php echo APP_PATH?>Tpl/Index/uploadify/uploadify.swf', 'uploader': '<?php echo APP_PATH?>Tpl/Index/uploadify/uploadify.php', 'buttonText':'上传图片', 'auto': false, 'multi': false, 'onUploadSuccess' : function(file, data, response) { alert("新图片名字是"+data); } });
参数说明:
#scroll_upload 是一个input type=file的按钮的id
$timestamp 是当前时间的时间戳 APP_PATH是当前项目的根目录,如后台使用,就是"./admin/"这样的(这里我也不是很懂啊,个人见解)
相关文章推荐
- jquery uploadify 实现批量上传,带进度显示,判断文件大小
- Jquery.Uploadify实现批量上传显示进度条 取消 上传后缩略图显示 可删除
- jQuery Uploadify上传插件使用中的问题 中文字符文件名转英文
- 使用jQuery Uploadify借助Dorado平台实现批量上传文件动态显示实时上传文件状态
- Jquery.Uploadify实现批量上传显示进度条 取消 上传后缩略图显示 可删除
- 在asp.net中使用jquery.uploadify-3.1实现上传
- jquery.uploadify插件实现图片上传和预览效果
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
- jquery uploadify 上传成功404 和 GET请求 404 Not Found
- jquery uploadify在谷歌浏和火狐下无法上传的解决方案
- jquery uploadify上传插件兼容火狐问题
- JQuery uploadify上传组件的使用方法
- ASP.NET jquery.uploadify上传控件中文乱码解决办法(转)
- 在SSH的基础上使用jquery.uploadify.js上传文件
- ASP.NET jquery.uploadify上传控件中文乱码解决办法
- Jquery Uploadify上传带进度条
- jquery.uploadify.min.js上传图片使用
- 解决jQuery uploadify在非IE核心浏览器下无法上传
- jquery uploadify上传文件http error
- JqueryUploadify上传文件(带进度条)