nouveau style menu_top
[mtweb] / mw / libs / tiny_mce / plugins / tinybrowser / upload_process.php
1 <?php\r
2 require_once('config_tinybrowser.php');\r
3 require_once('fns_tinybrowser.php');\r
4 \r
5 // delay script if set\r
6 if($tinybrowser['delayprocess']>0) sleep($tinybrowser['delayprocess']);\r
7 \r
8 // Initialise files array and error vars\r
9 $files = array();\r
10 $good = 0;\r
11 $bad = 0;\r
12 $dup = 0;\r
13 $total = (isset($_GET['filetotal']) ? $_GET['filetotal'] : 0);\r
14 \r
15 \r
16 // Assign get variables\r
17 $folder = $tinybrowser['docroot'].urldecode($_GET['folder']);\r
18 $foldernow = urlencode(str_replace($tinybrowser['path'][$_GET['type']],'',urldecode($_GET['folder'])));\r
19 $passfeid = (isset($_GET['feid']) ? '&feid='.$_GET['feid'] : '');\r
20 \r
21 if ($handle = opendir($folder))\r
22         {\r
23         while (false !== ($file = readdir($handle)))\r
24                 {\r
25                 if ($file != "." && $file != ".." && substr($file,-1)=='_')\r
26                         {\r
27                         //-- File Naming\r
28                         $tmp_filename = $folder.$file;\r
29                         $dest_filename   = $folder.rtrim($file,'_');\r
30         \r
31                         //-- Duplicate Files\r
32                         if(file_exists($dest_filename)) { unlink($tmp_filename); $dup++; continue; }\r
33 \r
34                         //-- Bad extensions\r
35                         $nameparts = explode('.',$dest_filename);\r
36                         $ext = end($nameparts);\r
37                         \r
38                         if(!validateExtension($ext, $tinybrowser['prohibited'])) { unlink($tmp_filename); continue; }\r
39         \r
40                         //-- Rename temp file to dest file\r
41                         rename($tmp_filename, $dest_filename);\r
42                         $good++;\r
43                         \r
44                         //-- if image, perform additional processing\r
45                         if($_GET['type']=='image')\r
46                                 {\r
47                                 //-- Good mime-types\r
48                                 $imginfo = getimagesize($dest_filename);\r
49                         if($imginfo === false) { unlink($dest_filename); continue; }\r
50                                 $mime = $imginfo['mime'];\r
51 \r
52                                 // resize image to maximum height and width, if set\r
53                                 if($tinybrowser['imageresize']['width'] > 0 || $tinybrowser['imageresize']['height'] > 0)\r
54                                         {\r
55                                         // assign new width and height values, only if they are less than existing image size\r
56                                         $widthnew  = ($tinybrowser['imageresize']['width'] > 0 && $tinybrowser['imageresize']['width'] < $imginfo[0] ? $tinybrowser['imageresize']['width'] : $imginfo[0]);\r
57                                         $heightnew = ($tinybrowser['imageresize']['height'] > 0 && $tinybrowser['imageresize']['height'] < $imginfo[1] ? $tinybrowser['imageresize']['height'] :  $imginfo[1]);\r
58 \r
59                                         // only resize if width or height values are different\r
60                                         if($widthnew != $imginfo[0] || $heightnew != $imginfo[1])\r
61                                                 {\r
62                                                 $im = convert_image($dest_filename,$mime);\r
63                                                 resizeimage($im,$widthnew,$heightnew,$dest_filename,$tinybrowser['imagequality'],$mime);\r
64                                                 imagedestroy($im);\r
65                                                 }\r
66                                         }\r
67 \r
68                                 // generate thumbnail\r
69                                 $thumbimg = $folder.'_thumbs/_'.rtrim($file,'_');\r
70                                 if (!file_exists($thumbimg))\r
71                                         {\r
72                                         $im = convert_image($dest_filename,$mime);\r
73                                         resizeimage     ($im,$tinybrowser['thumbsize'],$tinybrowser['thumbsize'],$thumbimg,$tinybrowser['thumbquality'],$mime);\r
74                                         imagedestroy ($im);\r
75                                         }\r
76                                 }\r
77 \r
78         }\r
79                 }\r
80         closedir($handle);\r
81         }\r
82 $bad = $total-($good+$dup);\r
83 \r
84 // Check for problem during upload\r
85 if($total>0 && $bad==$total) Header('Location: ./upload.php?type='.$_GET['type'].$passfeid.'&permerror=1&total='.$total);\r
86 else Header('Location: ./upload.php?type='.$_GET['type'].$passfeid.'&folder='.$foldernow.'&badfiles='.$bad.'&goodfiles='.$good.'&dupfiles='.$dup);\r
87 ?>\r
88 \r
89 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
90 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\r
91         <head>\r
92         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\r
93         <meta http-equiv="Pragma" content="no-cache" />\r
94                 <title>TinyBrowser :: Process Upload</title>\r
95         </head>\r
96         <body>\r
97                 <p>Sorry, there was an error processing file uploads.</p>\r
98         </body>\r
99 </html>\r