ueditor-rails 1.2.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +49 -0
  5. data/Rakefile +1 -0
  6. data/app/assets/javascripts/ueditor.js +3 -0
  7. data/lib/tasks/ueditor.rake +12 -0
  8. data/lib/ueditor-rails.rb +1 -0
  9. data/lib/ueditor/rails.rb +9 -0
  10. data/lib/ueditor/rails/engine.rb +20 -0
  11. data/lib/ueditor/rails/version.rb +6 -0
  12. data/ueditor-rails.gemspec +20 -0
  13. data/vendor/assets/javascripts/ueditor/.DS_Store +0 -0
  14. data/vendor/assets/javascripts/ueditor/dialogs/.DS_Store +0 -0
  15. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.css +43 -0
  16. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.html +54 -0
  17. data/vendor/assets/javascripts/ueditor/dialogs/emotion/emotion.js +186 -0
  18. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/0.gif +0 -0
  19. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/bface.gif +0 -0
  20. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/cface.gif +0 -0
  21. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/fface.gif +0 -0
  22. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/jxface2.gif +0 -0
  23. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/neweditor-tab-bg.png +0 -0
  24. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/tface.gif +0 -0
  25. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/wface.gif +0 -0
  26. data/vendor/assets/javascripts/ueditor/dialogs/emotion/images/yface.gif +0 -0
  27. data/vendor/assets/javascripts/ueditor/dialogs/image/image.css +69 -0
  28. data/vendor/assets/javascripts/ueditor/dialogs/image/image.html +204 -0
  29. data/vendor/assets/javascripts/ueditor/dialogs/image/image.js +712 -0
  30. data/vendor/assets/javascripts/ueditor/dialogs/image/imageUploader.swf +0 -0
  31. data/vendor/assets/javascripts/ueditor/dialogs/image/images/center_focus.jpg +0 -0
  32. data/vendor/assets/javascripts/ueditor/dialogs/image/images/left_focus.jpg +0 -0
  33. data/vendor/assets/javascripts/ueditor/dialogs/image/images/none_focus.jpg +0 -0
  34. data/vendor/assets/javascripts/ueditor/dialogs/image/images/right_focus.jpg +0 -0
  35. data/vendor/assets/javascripts/ueditor/dialogs/internal.js +79 -0
  36. data/vendor/assets/javascripts/ueditor/dialogs/tangram.js +1238 -0
  37. data/vendor/assets/javascripts/ueditor/dialogs/video/images/center_focus.jpg +0 -0
  38. data/vendor/assets/javascripts/ueditor/dialogs/video/images/left_focus.jpg +0 -0
  39. data/vendor/assets/javascripts/ueditor/dialogs/video/images/none_focus.jpg +0 -0
  40. data/vendor/assets/javascripts/ueditor/dialogs/video/images/right_focus.jpg +0 -0
  41. data/vendor/assets/javascripts/ueditor/dialogs/video/video.css +59 -0
  42. data/vendor/assets/javascripts/ueditor/dialogs/video/video.html +67 -0
  43. data/vendor/assets/javascripts/ueditor/dialogs/video/video.js +402 -0
  44. data/vendor/assets/javascripts/ueditor/editor_all.js +12437 -0
  45. data/vendor/assets/javascripts/ueditor/editor_all_min.js +1 -0
  46. data/vendor/assets/javascripts/ueditor/editor_config.js +209 -0
  47. data/vendor/assets/javascripts/ueditor/index.html +146 -0
  48. data/vendor/assets/javascripts/ueditor/lang/en/en.js +528 -0
  49. data/vendor/assets/javascripts/ueditor/lang/en/images/addimage.png +0 -0
  50. data/vendor/assets/javascripts/ueditor/lang/en/images/alldeletebtnhoverskin.png +0 -0
  51. data/vendor/assets/javascripts/ueditor/lang/en/images/alldeletebtnupskin.png +0 -0
  52. data/vendor/assets/javascripts/ueditor/lang/en/images/background.png +0 -0
  53. data/vendor/assets/javascripts/ueditor/lang/en/images/button.png +0 -0
  54. data/vendor/assets/javascripts/ueditor/lang/en/images/copy.png +0 -0
  55. data/vendor/assets/javascripts/ueditor/lang/en/images/deletedisable.png +0 -0
  56. data/vendor/assets/javascripts/ueditor/lang/en/images/deleteenable.png +0 -0
  57. data/vendor/assets/javascripts/ueditor/lang/en/images/imglabel.png +0 -0
  58. data/vendor/assets/javascripts/ueditor/lang/en/images/listbackground.png +0 -0
  59. data/vendor/assets/javascripts/ueditor/lang/en/images/localimage.png +0 -0
  60. data/vendor/assets/javascripts/ueditor/lang/en/images/music.png +0 -0
  61. data/vendor/assets/javascripts/ueditor/lang/en/images/rotateleftdisable.png +0 -0
  62. data/vendor/assets/javascripts/ueditor/lang/en/images/rotateleftenable.png +0 -0
  63. data/vendor/assets/javascripts/ueditor/lang/en/images/rotaterightdisable.png +0 -0
  64. data/vendor/assets/javascripts/ueditor/lang/en/images/rotaterightenable.png +0 -0
  65. data/vendor/assets/javascripts/ueditor/lang/en/images/upload.png +0 -0
  66. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/copy.png +0 -0
  67. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/imglabel.png +0 -0
  68. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/localimage.png +0 -0
  69. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/music.png +0 -0
  70. data/vendor/assets/javascripts/ueditor/lang/zh-cn/images/upload.png +0 -0
  71. data/vendor/assets/javascripts/ueditor/lang/zh-cn/zh-cn.js +492 -0
  72. data/vendor/assets/javascripts/ueditor/php/.DS_Store +0 -0
  73. data/vendor/assets/javascripts/ueditor/php/Uploader.class.php +198 -0
  74. data/vendor/assets/javascripts/ueditor/php/fileUp.php +43 -0
  75. data/vendor/assets/javascripts/ueditor/php/getContent.php +21 -0
  76. data/vendor/assets/javascripts/ueditor/php/getMovie.php +13 -0
  77. data/vendor/assets/javascripts/ueditor/php/getRemoteImage.php +100 -0
  78. data/vendor/assets/javascripts/ueditor/php/imageManager.php +56 -0
  79. data/vendor/assets/javascripts/ueditor/php/imageUp.php +48 -0
  80. data/vendor/assets/javascripts/ueditor/php/scrawlUp.php +60 -0
  81. data/vendor/assets/javascripts/ueditor/themes/.DS_Store +0 -0
  82. data/vendor/assets/javascripts/ueditor/themes/default/.DS_Store +0 -0
  83. data/vendor/assets/javascripts/ueditor/themes/default/css/ueditor.css +1582 -0
  84. data/vendor/assets/javascripts/ueditor/themes/default/dialogbase.css +100 -0
  85. data/vendor/assets/javascripts/ueditor/themes/default/images/.DS_Store +0 -0
  86. data/vendor/assets/javascripts/ueditor/themes/default/images/anchor.gif +0 -0
  87. data/vendor/assets/javascripts/ueditor/themes/default/images/arrow.png +0 -0
  88. data/vendor/assets/javascripts/ueditor/themes/default/images/button-bg.gif +0 -0
  89. data/vendor/assets/javascripts/ueditor/themes/default/images/cancelbutton.gif +0 -0
  90. data/vendor/assets/javascripts/ueditor/themes/default/images/cursor_h.gif +0 -0
  91. data/vendor/assets/javascripts/ueditor/themes/default/images/cursor_h.png +0 -0
  92. data/vendor/assets/javascripts/ueditor/themes/default/images/cursor_v.gif +0 -0
  93. data/vendor/assets/javascripts/ueditor/themes/default/images/cursor_v.png +0 -0
  94. data/vendor/assets/javascripts/ueditor/themes/default/images/dialog-title-bg.png +0 -0
  95. data/vendor/assets/javascripts/ueditor/themes/default/images/filescan.png +0 -0
  96. data/vendor/assets/javascripts/ueditor/themes/default/images/highlighted.gif +0 -0
  97. data/vendor/assets/javascripts/ueditor/themes/default/images/icons-all.gif +0 -0
  98. data/vendor/assets/javascripts/ueditor/themes/default/images/icons.gif +0 -0
  99. data/vendor/assets/javascripts/ueditor/themes/default/images/icons.png +0 -0
  100. data/vendor/assets/javascripts/ueditor/themes/default/images/lock.gif +0 -0
  101. data/vendor/assets/javascripts/ueditor/themes/default/images/neweditor-tab-bg.png +0 -0
  102. data/vendor/assets/javascripts/ueditor/themes/default/images/pagebreak.gif +0 -0
  103. data/vendor/assets/javascripts/ueditor/themes/default/images/scale.png +0 -0
  104. data/vendor/assets/javascripts/ueditor/themes/default/images/spacer.gif +0 -0
  105. data/vendor/assets/javascripts/ueditor/themes/default/images/sparator_v.png +0 -0
  106. data/vendor/assets/javascripts/ueditor/themes/default/images/toolbar_bg.png +0 -0
  107. data/vendor/assets/javascripts/ueditor/themes/default/images/unhighlighted.gif +0 -0
  108. data/vendor/assets/javascripts/ueditor/themes/default/images/upload.png +0 -0
  109. data/vendor/assets/javascripts/ueditor/themes/default/images/videologo.gif +0 -0
  110. data/vendor/assets/javascripts/ueditor/themes/default/images/word.gif +0 -0
  111. data/vendor/assets/javascripts/ueditor/themes/default/images/wordpaste.png +0 -0
  112. data/vendor/assets/javascripts/ueditor/themes/iframe.css +1 -0
  113. data/vendor/assets/javascripts/ueditor/uparse.js +358 -0
  114. metadata +159 -0
@@ -0,0 +1,198 @@
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: taoqili
5
+ * Date: 12-7-18
6
+ * Time: 上午11: 32
7
+ * UEditor编辑器通用上传类
8
+ */
9
+ class Uploader
10
+ {
11
+ private $fileField; //文件域名
12
+ private $file; //文件上传对象
13
+ private $config; //配置信息
14
+ private $oriName; //原始文件名
15
+ private $fileName; //新文件名
16
+ private $fullName; //完整文件名,即从当前配置目录开始的URL
17
+ private $fileSize; //文件大小
18
+ private $fileType; //文件类型
19
+ private $stateInfo; //上传状态信息,
20
+ private $stateMap = array( //上传状态映射表,国际化用户需考虑此处数据的国际化
21
+ "SUCCESS" , //上传成功标记,在UEditor中内不可改变,否则flash判断会出错
22
+ "文件大小超出 upload_max_filesize 限制" ,
23
+ "文件大小超出 MAX_FILE_SIZE 限制" ,
24
+ "文件未被完整上传" ,
25
+ "没有文件被上传" ,
26
+ "上传文件为空" ,
27
+ "POST" => "文件大小超出 post_max_size 限制" ,
28
+ "SIZE" => "文件大小超出网站限制" ,
29
+ "TYPE" => "不允许的文件类型" ,
30
+ "DIR" => "目录创建失败" ,
31
+ "IO" => "输入输出错误" ,
32
+ "UNKNOWN" => "未知错误" ,
33
+ "MOVE" => "文件保存时出错"
34
+ );
35
+
36
+ /**
37
+ * 构造函数
38
+ * @param string $fileField 表单名称
39
+ * @param array $config 配置项
40
+ * @param bool $base64 是否解析base64编码,可省略。若开启,则$fileField代表的是base64编码的字符串表单名
41
+ */
42
+ public function __construct( $fileField , $config , $base64 = false )
43
+ {
44
+ $this->fileField = $fileField;
45
+ $this->config = $config;
46
+ $this->stateInfo = $this->stateMap[ 0 ];
47
+ $this->upFile( $base64 );
48
+ }
49
+
50
+ /**
51
+ * 上传文件的主处理方法
52
+ * @param $base64
53
+ * @return mixed
54
+ */
55
+ private function upFile( $base64 )
56
+ {
57
+ //处理base64上传
58
+ if ( "base64" == $base64 ) {
59
+ $content = $_POST[ $this->fileField ];
60
+ $this->base64ToImage( $content );
61
+ return;
62
+ }
63
+
64
+ //处理普通上传
65
+ $file = $this->file = $_FILES[ $this->fileField ];
66
+ if ( !$file ) {
67
+ $this->stateInfo = $this->getStateInfo( 'POST' );
68
+ return;
69
+ }
70
+ if ( $this->file[ 'error' ] ) {
71
+ $this->stateInfo = $this->getStateInfo( $file[ 'error' ] );
72
+ return;
73
+ }
74
+ if ( !is_uploaded_file( $file[ 'tmp_name' ] ) ) {
75
+ $this->stateInfo = $this->getStateInfo( "UNKNOWN" );
76
+ return;
77
+ }
78
+
79
+ $this->oriName = $file[ 'name' ];
80
+ $this->fileSize = $file[ 'size' ];
81
+ $this->fileType = $this->getFileExt();
82
+
83
+ if ( !$this->checkSize() ) {
84
+ $this->stateInfo = $this->getStateInfo( "SIZE" );
85
+ return;
86
+ }
87
+ if ( !$this->checkType() ) {
88
+ $this->stateInfo = $this->getStateInfo( "TYPE" );
89
+ return;
90
+ }
91
+ $this->fullName = $this->getFolder() . '/' . $this->getName();
92
+ if ( $this->stateInfo == $this->stateMap[ 0 ] ) {
93
+ if ( !move_uploaded_file( $file[ "tmp_name" ] , $this->fullName ) ) {
94
+ $this->stateInfo = $this->getStateInfo( "MOVE" );
95
+ }
96
+ }
97
+ }
98
+
99
+ /**
100
+ * 处理base64编码的图片上传
101
+ * @param $base64Data
102
+ * @return mixed
103
+ */
104
+ private function base64ToImage( $base64Data )
105
+ {
106
+ $img = base64_decode( $base64Data );
107
+ $this->fileName = time() . rand( 1 , 10000 ) . ".png";
108
+ $this->fullName = $this->getFolder() . '/' . $this->fileName;
109
+ if ( !file_put_contents( $this->fullName , $img ) ) {
110
+ $this->stateInfo = $this->getStateInfo( "IO" );
111
+ return;
112
+ }
113
+ $this->oriName = "";
114
+ $this->fileSize = strlen( $img );
115
+ $this->fileType = ".png";
116
+ }
117
+
118
+ /**
119
+ * 获取当前上传成功文件的各项信息
120
+ * @return array
121
+ */
122
+ public function getFileInfo()
123
+ {
124
+ return array(
125
+ "originalName" => $this->oriName ,
126
+ "name" => $this->fileName ,
127
+ "url" => $this->fullName ,
128
+ "size" => $this->fileSize ,
129
+ "type" => $this->fileType ,
130
+ "state" => $this->stateInfo
131
+ );
132
+ }
133
+
134
+ /**
135
+ * 上传错误检查
136
+ * @param $errCode
137
+ * @return string
138
+ */
139
+ private function getStateInfo( $errCode )
140
+ {
141
+ return !$this->stateMap[ $errCode ] ? $this->stateMap[ "UNKNOWN" ] : $this->stateMap[ $errCode ];
142
+ }
143
+
144
+ /**
145
+ * 重命名文件
146
+ * @return string
147
+ */
148
+ private function getName()
149
+ {
150
+ return $this->fileName = time() . rand( 1 , 10000 ) . $this->getFileExt();
151
+ }
152
+
153
+ /**
154
+ * 文件类型检测
155
+ * @return bool
156
+ */
157
+ private function checkType()
158
+ {
159
+ return in_array( $this->getFileExt() , $this->config[ "allowFiles" ] );
160
+ }
161
+
162
+ /**
163
+ * 文件大小检测
164
+ * @return bool
165
+ */
166
+ private function checkSize()
167
+ {
168
+ return $this->fileSize <= ( $this->config[ "maxSize" ] * 1024 );
169
+ }
170
+
171
+ /**
172
+ * 获取文件扩展名
173
+ * @return string
174
+ */
175
+ private function getFileExt()
176
+ {
177
+ return strtolower( strrchr( $this->file[ "name" ] , '.' ) );
178
+ }
179
+
180
+ /**
181
+ * 按照日期自动创建存储文件夹
182
+ * @return string
183
+ */
184
+ private function getFolder()
185
+ {
186
+ $pathStr = $this->config[ "savePath" ];
187
+ if ( strrchr( $pathStr , "/" ) != "/" ) {
188
+ $pathStr .= "/";
189
+ }
190
+ $pathStr .= date( "Ymd" );
191
+ if ( !file_exists( $pathStr ) ) {
192
+ if ( !mkdir( $pathStr , 0777 , true ) ) {
193
+ return false;
194
+ }
195
+ }
196
+ return $pathStr;
197
+ }
198
+ }
@@ -0,0 +1,43 @@
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: taoqili
5
+ * Date: 12-7-26
6
+ * Time: 上午10:32
7
+ */
8
+ header("Content-Type: text/html; charset=utf-8");
9
+ error_reporting( E_ERROR | E_WARNING );
10
+ include "Uploader.class.php";
11
+ //上传配置
12
+ $config = array(
13
+ "savePath" => "upload/" , //保存路径
14
+ "allowFiles" => array( ".rar" , ".doc" , ".docx" , ".zip" , ".pdf" , ".txt" , ".swf" , ".wmv" ) , //文件允许格式
15
+ "maxSize" => 100000 //文件大小限制,单位KB
16
+ );
17
+ //生成上传实例对象并完成上传
18
+ $up = new Uploader( "upfile" , $config );
19
+
20
+ /**
21
+ * 得到上传文件所对应的各个参数,数组结构
22
+ * array(
23
+ * "originalName" => "", //原始文件名
24
+ * "name" => "", //新文件名
25
+ * "url" => "", //返回的地址
26
+ * "size" => "", //文件大小
27
+ * "type" => "" , //文件类型
28
+ * "state" => "" //上传状态,上传成功时必须返回"SUCCESS"
29
+ * )
30
+ */
31
+ $info = $up->getFileInfo();
32
+
33
+ /**
34
+ * 向浏览器返回数据json数据
35
+ * {
36
+ * 'url' :'a.rar', //保存后的文件路径
37
+ * 'fileType' :'.rar', //文件描述,对图片来说在前端会添加到title属性上
38
+ * 'original' :'编辑器.jpg', //原始文件名
39
+ * 'state' :'SUCCESS' //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中
40
+ * }
41
+ */
42
+ echo '{"url":"' .$info[ "url" ] . '","fileType":"' . $info[ "type" ] . '","original":"' . $info[ "originalName" ] . '","state":"' . $info["state"] . '"}';
43
+
@@ -0,0 +1,21 @@
1
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
2
+ <script src="../uparse.js" type="text/javascript"></script>
3
+ <script>
4
+ uParse('.content',{
5
+ 'highlightJsUrl':'../third-party/SyntaxHighlighter/shCore.js',
6
+ 'highlightCssUrl':'../third-party/SyntaxHighlighter/shCoreDefault.css'
7
+ })
8
+ </script>
9
+ <?php
10
+ //获取数据
11
+ error_reporting(E_ERROR|E_WARNING);
12
+ $content = htmlspecialchars(stripslashes($_POST['myEditor']));
13
+ $content1 = htmlspecialchars(stripslashes($_POST['myEditor1']));
14
+
15
+ //存入数据库或者其他操作
16
+
17
+ //显示
18
+ echo "第1个编辑器的值";
19
+ echo "<div class='content'>".htmlspecialchars_decode($content)."</div>";
20
+ echo "<br/>第2个编辑器的值<br/>";
21
+ echo "<textarea class='content' style='width:500px;height:300px;'>".htmlspecialchars_decode($content1)."</textarea><br/>";
@@ -0,0 +1,13 @@
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: taoqili
5
+ * Date: 12-2-19
6
+ * Time: 下午10:44
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+ error_reporting(E_ERROR|E_WARNING);
10
+ $key =htmlspecialchars($_POST["searchKey"]);
11
+ $type = htmlspecialchars($_POST["videoType"]);
12
+ $html = file_get_contents('http://api.tudou.com/v3/gw?method=item.search&appKey=myKey&format=json&kw='.$key.'&pageNo=1&pageSize=20&channelId='.$type.'&inDays=7&media=v&sort=s');
13
+ echo $html;
@@ -0,0 +1,100 @@
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: taoqili
5
+ * Date: 11-12-28
6
+ * Time: 上午9:54
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+ header("Content-Type: text/html; charset=utf-8");
10
+ error_reporting(E_ERROR|E_WARNING);
11
+ //远程抓取图片配置
12
+ $config = array(
13
+ "savePath" => "upload/" , //保存路径
14
+ "allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" ) , //文件允许格式
15
+ "maxSize" => 3000 //文件大小限制,单位KB
16
+ );
17
+ $uri = htmlspecialchars( $_POST[ 'upfile' ] );
18
+ $uri = str_replace( "&amp;" , "&" , $uri );
19
+ getRemoteImage( $uri,$config );
20
+
21
+ /**
22
+ * 远程抓取
23
+ * @param $uri
24
+ * @param $config
25
+ */
26
+ function getRemoteImage( $uri,$config)
27
+ {
28
+ //忽略抓取时间限制
29
+ set_time_limit( 0 );
30
+ //ue_separate_ue ue用于传递数据分割符号
31
+ $imgUrls = explode( "ue_separate_ue" , $uri );
32
+ $tmpNames = array();
33
+ foreach ( $imgUrls as $imgUrl ) {
34
+ //http开头验证
35
+ if(strpos($imgUrl,"http")!==0){
36
+ array_push( $tmpNames , "error" );
37
+ continue;
38
+ }
39
+ //获取请求头
40
+ $heads = get_headers( $imgUrl );
41
+ //死链检测
42
+ if ( !( stristr( $heads[ 0 ] , "200" ) && stristr( $heads[ 0 ] , "OK" ) ) ) {
43
+ array_push( $tmpNames , "error" );
44
+ continue;
45
+ }
46
+
47
+ //格式验证(扩展名验证和Content-Type验证)
48
+ $fileType = strtolower( strrchr( $imgUrl , '.' ) );
49
+ if ( !in_array( $fileType , $config[ 'allowFiles' ] ) || stristr( $heads[ 'Content-Type' ] , "image" ) ) {
50
+ array_push( $tmpNames , "error" );
51
+ continue;
52
+ }
53
+
54
+ //打开输出缓冲区并获取远程图片
55
+ ob_start();
56
+ $context = stream_context_create(
57
+ array (
58
+ 'http' => array (
59
+ 'follow_location' => false // don't follow redirects
60
+ )
61
+ )
62
+ );
63
+ //请确保php.ini中的fopen wrappers已经激活
64
+ readfile( $imgUrl,false,$context);
65
+ $img = ob_get_contents();
66
+ ob_end_clean();
67
+
68
+ //大小验证
69
+ $uriSize = strlen( $img ); //得到图片大小
70
+ $allowSize = 1024 * $config[ 'maxSize' ];
71
+ if ( $uriSize > $allowSize ) {
72
+ array_push( $tmpNames , "error" );
73
+ continue;
74
+ }
75
+ //创建保存位置
76
+ $savePath = $config[ 'savePath' ];
77
+ if ( !file_exists( $savePath ) ) {
78
+ mkdir( "$savePath" , 0777 );
79
+ }
80
+ //写入文件
81
+ $tmpName = $savePath . rand( 1 , 10000 ) . time() . strrchr( $imgUrl , '.' );
82
+ try {
83
+ $fp2 = @fopen( $tmpName , "a" );
84
+ fwrite( $fp2 , $img );
85
+ fclose( $fp2 );
86
+ array_push( $tmpNames , $tmpName );
87
+ } catch ( Exception $e ) {
88
+ array_push( $tmpNames , "error" );
89
+ }
90
+ }
91
+ /**
92
+ * 返回数据格式
93
+ * {
94
+ * 'url' : '新地址一ue_separate_ue新地址二ue_separate_ue新地址三',
95
+ * 'srcUrl': '原始地址一ue_separate_ue原始地址二ue_separate_ue原始地址三',
96
+ * 'tip' : '状态提示'
97
+ * }
98
+ */
99
+ echo "{'url':'" . implode( "ue_separate_ue" , $tmpNames ) . "','tip':'远程图片抓取成功!','srcUrl':'" . $uri . "'}";
100
+ }
@@ -0,0 +1,56 @@
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: taoqili
5
+ * Date: 12-1-16
6
+ * Time: 上午11:44
7
+ * To change this template use File | Settings | File Templates.
8
+ */
9
+ header("Content-Type: text/html; charset=utf-8");
10
+ error_reporting( E_ERROR | E_WARNING );
11
+
12
+ //需要遍历的目录列表,最好使用缩略图地址,否则当网速慢时可能会造成严重的延时
13
+ $paths = array('upload/','upload1/');
14
+
15
+ $action = htmlspecialchars( $_POST[ "action" ] );
16
+ if ( $action == "get" ) {
17
+ $files = array();
18
+ foreach ( $paths as $path){
19
+ $tmp = getfiles( $path );
20
+ if($tmp){
21
+ $files = array_merge($files,$tmp);
22
+ }
23
+ }
24
+ if ( !count($files) ) return;
25
+ rsort($files,SORT_STRING);
26
+ $str = "";
27
+ foreach ( $files as $file ) {
28
+ $str .= $file . "ue_separate_ue";
29
+ }
30
+ echo $str;
31
+ }
32
+
33
+ /**
34
+ * 遍历获取目录下的指定类型的文件
35
+ * @param $path
36
+ * @param array $files
37
+ * @return array
38
+ */
39
+ function getfiles( $path , &$files = array() )
40
+ {
41
+ if ( !is_dir( $path ) ) return null;
42
+ $handle = opendir( $path );
43
+ while ( false !== ( $file = readdir( $handle ) ) ) {
44
+ if ( $file != '.' && $file != '..' ) {
45
+ $path2 = $path . '/' . $file;
46
+ if ( is_dir( $path2 ) ) {
47
+ getfiles( $path2 , $files );
48
+ } else {
49
+ if ( preg_match( "/\.(gif|jpeg|jpg|png|bmp)$/i" , $file ) ) {
50
+ $files[] = $path2;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ return $files;
56
+ }
@@ -0,0 +1,48 @@
1
+ <?php
2
+ /**
3
+ * Created by JetBrains PhpStorm.
4
+ * User: taoqili
5
+ * Date: 12-7-18
6
+ * Time: 上午10:42
7
+ */
8
+ header("Content-Type: text/html; charset=utf-8");
9
+ error_reporting(E_ERROR | E_WARNING);
10
+ include "Uploader.class.php";
11
+ //上传图片框中的描述表单名称,
12
+ $title = htmlspecialchars($_POST['pictitle'], ENT_QUOTES);
13
+ $path = htmlspecialchars($_POST['dir'], ENT_QUOTES);
14
+
15
+ //上传配置
16
+ $config = array(
17
+ "savePath" => ($path == "1" ? "upload/" : "upload1/"),
18
+ "maxSize" => 1000, //单位KB
19
+ "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp")
20
+ );
21
+
22
+ //生成上传实例对象并完成上传
23
+ $up = new Uploader("upfile", $config);
24
+
25
+ /**
26
+ * 得到上传文件所对应的各个参数,数组结构
27
+ * array(
28
+ * "originalName" => "", //原始文件名
29
+ * "name" => "", //新文件名
30
+ * "url" => "", //返回的地址
31
+ * "size" => "", //文件大小
32
+ * "type" => "" , //文件类型
33
+ * "state" => "" //上传状态,上传成功时必须返回"SUCCESS"
34
+ * )
35
+ */
36
+ $info = $up->getFileInfo();
37
+
38
+ /**
39
+ * 向浏览器返回数据json数据
40
+ * {
41
+ * 'url' :'a.jpg', //保存后的文件路径
42
+ * 'title' :'hello', //文件描述,对图片来说在前端会添加到title属性上
43
+ * 'original' :'b.jpg', //原始文件名
44
+ * 'state' :'SUCCESS' //上传状态,成功时返回SUCCESS,其他任何值将原样返回至图片上传框中
45
+ * }
46
+ */
47
+ echo "{'url':'" . $info["url"] . "','title':'" . $title . "','original':'" . $info["originalName"] . "','state':'" . $info["state"] . "'}";
48
+