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

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