source: temp/trunk/data/class/SC_UploadFile.php @ 9272

Revision 9272, 8.4 KB checked in by kakinaka, 20 years ago (diff)

blank

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/*
3 * Copyright(c) 2000-2006 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8$SC_UPLOADFILE_DIR = realpath(dirname( __FILE__));
9require_once($SC_UPLOADFILE_DIR . "/../lib/gdthumb.php");   
10
11/* ¥¢¥Ã¥×¥í¡¼¥É¥Õ¥¡¥¤¥ë´ÉÍý¥¯¥é¥¹ */
12class SC_UploadFile {
13    var $temp_dir;
14    var $save_dir;
15    var $keyname;   // ¥Õ¥¡¥¤¥ëinput¥¿¥°¤Îname
16    var $width;     // ²£¥µ¥¤¥º
17    var $height;    // ½Ä¥µ¥¤¥º
18    var $arrExt;    // »ØÄꤹ¤ë³ÈÄ¥»Ò
19    var $temp_file; // Êݸ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë̾
20    var $save_file; // DB¤«¤éÆÉ¤ß½Ð¤·¤¿¥Õ¥¡¥¤¥ë̾
21    var $disp_name; // ¹àÌÜ̾
22    var $size;      // À©¸Â¥µ¥¤¥º
23    var $necessary; // ɬ¿Ü¤Î¾ì¹ç:true
24    var $image;     // ²èÁü¤Î¾ì¹ç:true
25   
26    // ¥Õ¥¡¥¤¥ë´ÉÍý¥¯¥é¥¹
27    function SC_UploadFile($temp_dir, $save_dir) {
28        $this->temp_dir = $temp_dir;
29        $this->save_dir = $save_dir;
30        $this->file_max = 0;
31    }
32
33    // ¥Õ¥¡¥¤¥ë¾ðÊóÄɲÃ
34    function addFile($disp_name, $keyname, $arrExt, $size, $necessary=false, $width=0, $height=0, $image=true) {
35        $this->disp_name[] = $disp_name;
36        $this->keyname[] = $keyname;
37        $this->width[] = $width;
38        $this->height[] = $height;
39        $this->arrExt[] = $arrExt;
40        $this->size[] = $size;
41        $this->necessary[] = $necessary;
42        $this->image[] = $image;
43    }
44    // ¥µ¥à¥Í¥¤¥ë²èÁü¤ÎºîÀ®
45    function makeThumb($src_file, $width, $height) {
46        // °ì°Õ¤ÊID¤ò¼èÆÀ¤¹¤ë¡£
47        $uniqname = date("mdHi") . "_" . uniqid("");
48       
49        $dst_file = $this->temp_dir . $uniqname;
50       
51        $objThumb = new gdthumb();
52        $ret = $objThumb->Main($src_file, $width, $height, $dst_file);
53       
54        if($ret[0] != 1) {
55            // ¥¨¥é¡¼¥á¥Ã¥»¡¼¥¸¤Îɽ¼¨
56            print($ret[1]);
57            exit;
58        }
59       
60        return basename($ret[1]);
61    }
62       
63    // ¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤¿¥Õ¥¡¥¤¥ë¤òÊݸ¤¹¤ë¡£
64    function makeTempFile($keyname, $rename = true) {
65        $objErr = new SC_CheckError();
66        $cnt = 0;
67        if(!($_FILES[$keyname]['size'] > 0)) {
68            $objErr->arrErr[$keyname] = "¢¨ " . $this->disp_name[$cnt] . "¤¬¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£<br />";
69        } else {
70            foreach($this->keyname as $val) {
71                // °ìÃפ·¤¿¥­¡¼¤Î¥Õ¥¡¥¤¥ë¤Ë¾ðÊó¤òÊݸ¤¹¤ë¡£
72                if ($val == $keyname) {
73                    // ³ÈÄ¥»Ò¥Á¥§¥Ã¥¯
74                    $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->arrExt[$cnt]), array("FILE_EXT_CHECK"));
75                    // ¥Õ¥¡¥¤¥ë¥µ¥¤¥º¥Á¥§¥Ã¥¯
76                    $objErr->doFunc(array($this->disp_name[$cnt], $keyname, $this->size[$cnt]), array("FILE_SIZE_CHECK"));
77                    // ¥¨¥é¡¼¤¬¤Ê¤¤¾ì¹ç
78                    if(!isset($objErr->arrErr[$keyname])) {
79                        // ²èÁü¥Õ¥¡¥¤¥ë¤Î¾ì¹ç
80                        if($this->image[$cnt]) {
81                            $this->temp_file[$cnt] = $this->makeThumb($_FILES[$keyname]['tmp_name'], $this->width[$cnt], $this->height[$cnt]);
82                        // ²èÁü¥Õ¥¡¥¤¥ë°Ê³°¤Î¾ì¹ç
83                        } else {
84                            // °ì°Õ¤Ê¥Õ¥¡¥¤¥ë̾¤òºîÀ®¤¹¤ë¡£
85                            if($rename) {
86                                $uniqname = date("mdHi") . "_" . uniqid("").".";
87                                $this->temp_file[$cnt] = ereg_replace("^.*\.",$uniqname, $_FILES[$keyname]['name']);
88                            } else {
89                                $this->temp_file[$cnt] = $_FILES[$keyname]['name'];
90                            }
91                            $result  = copy($_FILES[$keyname]['tmp_name'], $this->temp_dir. "/". $this->temp_file[$cnt]);
92                            gfPrintLog($_FILES[$keyname]['name']." -> ".$this->temp_dir. "/". $this->temp_file[$cnt]);
93                        }
94                    }
95                }
96                $cnt++;
97            }
98        }
99        return $objErr->arrErr[$keyname];
100    }
101
102    // ²èÁü¤òºï½ü¤¹¤ë¡£
103    function deleteFile($keyname) {
104        $objImage = new SC_Image($this->temp_dir);
105        $cnt = 0;
106        foreach($this->keyname as $val) {
107            if ($val == $keyname) {
108                // °ì»þ¥Õ¥¡¥¤¥ë¤Î¾ì¹çºï½ü¤¹¤ë¡£
109                if($this->temp_file[$cnt] != "") {
110                    $objImage->deleteImage($this->temp_file[$cnt], $this->save_dir);
111                }
112                $this->temp_file[$cnt] = "";
113                $this->save_file[$cnt] = "";
114            }
115            $cnt++;
116        }
117    }
118   
119    // °ì»þ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤ò¼èÆÀ¤¹¤ë¡£
120    function getTempFilePath($keyname) {
121        $cnt = 0;
122        $filepath = "";
123        foreach($this->keyname as $val) {
124            if ($val == $keyname) {
125                if($this->temp_file[$cnt] != "") {
126                    $filepath = $this->temp_dir . "/" . $this->temp_file[$cnt];
127                }
128            }
129            $cnt++;
130        }
131        return $filepath;
132    }
133   
134    // °ì»þ¥Õ¥¡¥¤¥ë¤òÊݸ¥Ç¥£¥ì¥¯¥È¥ê¤Ë°Ü¤¹
135    function moveTempFile() {
136        $cnt = 0;
137        $objImage = new SC_Image($this->temp_dir);
138       
139        foreach($this->keyname as $val) {
140            if($this->temp_file[$cnt] != "") {
141                                                   
142                $objImage->moveTempImage($this->temp_file[$cnt], $this->save_dir);
143                // ¤¹¤Ç¤ËÊݸ¥Õ¥¡¥¤¥ë¤¬¤¢¤Ã¤¿¾ì¹ç¤Ïºï½ü¤¹¤ë¡£
144                if($this->save_file[$cnt] != "" && !ereg("^sub/", $this->save_file[$cnt])) {
145                    $objImage->deleteImage($this->save_file[$cnt], $this->save_dir);
146                }
147            }
148            $cnt++;
149        }
150    }
151   
152    // HIDDENÍѤΥե¡¥¤¥ë̾ÇÛÎó¤òÊÖ¤¹
153    function getHiddenFileList() {
154        $cnt = 0;
155        foreach($this->keyname as $val) {
156            if($this->temp_file[$cnt] != "") {
157                $arrRet["temp_" . $val] = $this->temp_file[$cnt];
158            }
159            if($this->save_file[$cnt] != "") {
160                $arrRet["save_" . $val] = $this->save_file[$cnt];
161            }
162            $cnt++;
163        }
164        return $arrRet;
165    }
166   
167    // HIDDEN¤ÇÁ÷¤é¤ì¤Æ¤­¤¿¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ¤¹¤ë
168    function setHiddenFileList($arrPOST) {
169        $cnt = 0;
170        foreach($this->keyname as $val) {
171            $key = "temp_" . $val;
172            if($arrPOST[$key] != "") {
173                $this->temp_file[$cnt] = $arrPOST[$key];
174            }
175            $key = "save_" . $val;
176            if($arrPOST[$key] != "") {
177                $this->save_file[$cnt] = $arrPOST[$key];
178            }
179            $cnt++;
180        }
181    }
182   
183    // ¥Õ¥©¡¼¥à¤ËÅϤ¹ÍѤΥե¡¥¤¥ë¾ðÊóÇÛÎó¤òÊÖ¤¹
184    function getFormFileList($temp_url, $save_url, $real_size = false) {
185
186        $cnt = 0;
187        foreach($this->keyname as $val) {
188            if($this->temp_file[$cnt] != "") {
189                // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¥Á¥§¥Ã¥¯(¥Ñ¥¹¤Î¥¹¥é¥Ã¥·¥å/¤¬Ï¢Â³¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£)
190                if(ereg("/$", $temp_url)) {
191                    $arrRet[$val]['filepath'] = $temp_url . $this->temp_file[$cnt];
192                } else {
193                    $arrRet[$val]['filepath'] = $temp_url . "/" . $this->temp_file[$cnt];
194                }
195                $arrRet[$val]['filepath_dir'] = $this->temp_dir . $this->temp_file[$cnt];
196            } elseif ($this->save_file[$cnt] != "") {
197                // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¥Á¥§¥Ã¥¯(¥Ñ¥¹¤Î¥¹¥é¥Ã¥·¥å/¤¬Ï¢Â³¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£)
198                if(ereg("/$", $save_url)) {
199                    $arrRet[$val]['filepath'] = $save_url . $this->save_file[$cnt];
200                } else {
201                    $arrRet[$val]['filepath'] = $save_url . "/" . $this->save_file[$cnt];
202                }
203                $arrRet[$val]['filepath_dir'] = $this->save_dir . $this->save_file[$cnt];
204            }
205            if($arrRet[$val]['filepath'] != "") {
206               
207                if($real_size){
208                    list($width, $height) = getimagesize($arrRet[$val]['filepath_dir']);
209                    // ¥Õ¥¡¥¤¥ë²£Éý
210                    $arrRet[$val]['width'] = $width;
211                    // ¥Õ¥¡¥¤¥ë½ÄÉý
212                    $arrRet[$val]['height'] = $height;
213                }else{
214                    // ¥Õ¥¡¥¤¥ë²£Éý
215                    $arrRet[$val]['width'] = $this->width[$cnt];
216                    // ¥Õ¥¡¥¤¥ë½ÄÉý
217                    $arrRet[$val]['height'] = $this->height[$cnt];
218                }
219                // ɽ¼¨Ì¾
220                $arrRet[$val]['disp_name'] = $this->disp_name[$cnt];
221            }
222            $cnt++;
223        }
224        return $arrRet;
225    }
226   
227    // DBÊݸÍѤΥե¡¥¤¥ë̾ÇÛÎó¤òÊÖ¤¹
228    function getDBFileList() {
229        $cnt = 0;
230        foreach($this->keyname as $val) {
231            if($this->temp_file[$cnt] != "") {
232                $arrRet[$val] = $this->temp_file[$cnt];
233            } else  {
234                $arrRet[$val] = $this->save_file[$cnt];
235            }
236            $cnt++;
237        }
238        return $arrRet;
239    }
240   
241    // DB¤ÇÊݸ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë̾ÇÛÎó¤ò¥»¥Ã¥È¤¹¤ë
242    function setDBFileList($arrVal) {
243        $cnt = 0;
244        foreach($this->keyname as $val) {
245            if($arrVal[$val] != "") {
246                $this->save_file[$cnt] = $arrVal[$val];
247            }
248            $cnt++;
249        }
250    }
251   
252    // ²èÁü¤ò¥»¥Ã¥È¤¹¤ë
253    function setDBImageList($arrVal) {
254        $cnt = 0;
255        foreach($this->keyname as $val) {
256            if($arrVal[$val] != "" && $val == 'tv_products_image') {
257                $this->save_file[$cnt] = $arrVal[$val];
258            }
259            $cnt++;
260        }
261    }
262   
263    // DB¾å¤Î¥Õ¥¡¥¤¥ë¤ÎÆâºï½üÍ׵᤬¤¢¤Ã¤¿¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë¡£
264    function deleteDBFile($arrVal) {
265        $objImage = new SC_Image($this->temp_dir);
266        $cnt = 0;
267        foreach($this->keyname as $val) {
268            if($arrVal[$val] != "") {
269                if($this->save_file[$cnt] == "" && !ereg("^sub/", $arrVal[$val])) {
270                    $objImage->deleteImage($arrVal[$val], $this->save_dir);
271                }
272            }
273            $cnt++;
274        }
275    }
276   
277    // ɬ¿ÜȽÄê
278    function checkEXISTS($keyname = "") {
279        $cnt = 0;
280        $arrRet = array();
281        foreach($this->keyname as $val) {
282            if($val == $keyname || $keyname == "") {
283                // ɬ¿Ü¤Ç¤¢¤ì¤Ð¥¨¥é¡¼¥Á¥§¥Ã¥¯
284                if ($this->necessary[$cnt] == true) {
285                    if($this->save_file[$cnt] == "" && $this->temp_file[$cnt] == "") {
286                        $arrRet[$val] = "¢¨ " . $this->disp_name[$cnt] . "¤¬¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£<br>";
287                    }
288                }
289            }
290            $cnt++;
291        }
292        return $arrRet;
293    }
294       
295    // ³ÈÂçΨ¤ò»ØÄꤷ¤Æ²èÁüÊݸ
296    function saveResizeImage($keyname, $to_w, $to_h) {
297        $path = "";
298       
299        // keyname¤ÎźÉÕ¥Õ¥¡¥¤¥ë¤ò¼èÆÀ
300        $arrImageKey = array_flip($this->keyname);
301        $file = $this->temp_file[$arrImageKey[$keyname]];
302        $filepath = $this->temp_dir . $file;
303       
304        $path = $this->makeThumb($filepath, $to_w, $to_h);
305       
306        // ¥Õ¥¡¥¤¥ë̾¤À¤±ÊÖ¤¹
307        return basename($path);
308    }
309}
310?>
Note: See TracBrowser for help on using the repository browser.