From 0e4350526b9fc121bd4ecedac6ccae58134a6eaa Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Mon, 26 May 2014 11:26:56 +0800 Subject: [PATCH] add ie6/7 image preview feature --- .gitignore | 1 + examples/upload.js | 26 +++++++++++++----- server/fileupload.php | 13 ++++----- server/preview.php | 63 +++++++++++++++++++++++++++++++++++++++++++ src/widgets/image.js | 2 ++ 5 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 server/preview.php diff --git a/.gitignore b/.gitignore index 587361466..490f5453f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /node_modules /doc server/* +!server/preview.php !server/fileupload.php !server/fileupload2.php !server/crossdomain.xml diff --git a/examples/upload.js b/examples/upload.js index 72b76e1d1..7a2d34201 100644 --- a/examples/upload.js +++ b/examples/upload.js @@ -150,7 +150,7 @@ i = 0, // 修改js类型 unAllowed = 'text/plain;application/javascript '; - + for ( ; i < len; i++ ) { // 如果在列表里面 if ( ~unAllowed.indexOf( items[ i ].type ) ) { @@ -222,16 +222,30 @@ // @todo lazyload $wrap.text( '预览中' ); uploader.makeThumb( file, function( error, src ) { + var img; + if ( error ) { $wrap.text( '不能预览' ); return; } - if( !isSupportBase64 ) { - // 针对不支持base64的浏览器单独处理 - // src = 'http://f9.topit.me/9/dd/6d/11206448174286ddd9l.jpg'; + + if( isSupportBase64 ) { + img = $(''); + $wrap.empty().append( img ); + } else { + $.ajax('../server/preview.php', { + method: 'POST', + data: src, + dataType:'json' + }).done(function( response ) { + if (response.result) { + img = $(''); + $wrap.empty().append( img ); + } else { + $wrap.text("预览出错"); + } + }); } - var img = $(''); - $wrap.empty().append( img ); }, thumbnailWidth, thumbnailHeight ); percentages[ file.id ] = [ file.size, 0 ]; diff --git a/server/fileupload.php b/server/fileupload.php index 6527ea998..cbfbf49bb 100644 --- a/server/fileupload.php +++ b/server/fileupload.php @@ -9,6 +9,10 @@ * Contributing: http://www.plupload.com/contributing */ +#!! 注意 +#!! 此文件只是个示例,不要用于真正的产品之中。 +#!! 不保证代码安全性。 + #!! IMPORTANT: #!! this file is just an example, it doesn't incorporate any security checks and #!! is not recommended to be used in production environment as it is. Be sure to @@ -47,7 +51,7 @@ @set_time_limit(5 * 60); // Uncomment this one to fake upload time -usleep(5000); +// usleep(5000); // Settings // $targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload"; @@ -77,13 +81,6 @@ $fileName = uniqid("file_"); } -$md5File = @file('md5list.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); -$md5File = $md5File ? $md5File : array(); - -if (isset($_REQUEST["md5"]) && array_search($_REQUEST["md5"], $md5File ) !== FALSE ) { - die('{"jsonrpc" : "2.0", "result" : null, "id" : "id", "exist": 1}'); -} - $filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName; $uploadPath = $uploadDir . DIRECTORY_SEPARATOR . $fileName; diff --git a/server/preview.php b/server/preview.php new file mode 100644 index 000000000..320bf3de3 --- /dev/null +++ b/server/preview.php @@ -0,0 +1,63 @@ +