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

Revision 5922, 7.5 KB checked in by kakinaka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2/*
3 * Copyright ¢í 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) {
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                            $uniqname = date("mdHi") . "_" . uniqid("").".";
86                            $this->temp_file[$cnt] = ereg_replace("^.*\.",$uniqname, $_FILES[$keyname]['name']);
87                            $result  = copy($_FILES[$keyname]['tmp_name'], $this->temp_dir. "/". $this->temp_file[$cnt]);
88                            gfPrintLog($_FILES[$keyname]['name']." -> ".$this->temp_dir. "/". $this->temp_file[$cnt]);
89                        }
90                    }
91                }
92                $cnt++;
93            }
94        }
95        return $objErr->arrErr[$keyname];
96    }
97       
98    // ²èÁü¤òºï½ü¤¹¤ë¡£
99    function deleteFile($keyname) {
100        $objImage = new SC_Image($this->temp_dir);
101        $cnt = 0;
102        foreach($this->keyname as $val) {
103            if ($val == $keyname) {
104                // °ì»þ¥Õ¥¡¥¤¥ë¤Î¾ì¹çºï½ü¤¹¤ë¡£
105                if($this->temp_file[$cnt] != "") {
106                    $objImage->deleteImage($this->temp_file[$cnt], $this->save_dir);
107                }
108                $this->temp_file[$cnt] = "";
109                $this->save_file[$cnt] = "";
110            }
111            $cnt++;
112        }
113    }
114   
115    // °ì»þ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤ò¼èÆÀ¤¹¤ë¡£
116    function getTempFilePath($keyname) {
117        $cnt = 0;
118        $filepath = "";
119        foreach($this->keyname as $val) {
120            if ($val == $keyname) {
121                if($this->temp_file[$cnt] != "") {
122                    $filepath = $this->temp_dir . "/" . $this->temp_file[$cnt];
123                }
124            }
125            $cnt++;
126        }
127        return $filepath;
128    }
129   
130    // °ì»þ¥Õ¥¡¥¤¥ë¤òÊݸ¥Ç¥£¥ì¥¯¥È¥ê¤Ë°Ü¤¹
131    function moveTempFile() {
132        $cnt = 0;
133        $objImage = new SC_Image($this->temp_dir);
134       
135        foreach($this->keyname as $val) {
136            if($this->temp_file[$cnt] != "") {
137                                                   
138                $objImage->moveTempImage($this->temp_file[$cnt], $this->save_dir);
139                // ¤¹¤Ç¤ËÊݸ¥Õ¥¡¥¤¥ë¤¬¤¢¤Ã¤¿¾ì¹ç¤Ïºï½ü¤¹¤ë¡£
140                if($this->save_file[$cnt] != "" && !ereg("^sub/", $this->save_file[$cnt])) {
141                    $objImage->deleteImage($this->save_file[$cnt], $this->save_dir);
142                }
143            }
144            $cnt++;
145        }
146    }
147   
148    // HIDDENÍѤΥե¡¥¤¥ë̾ÇÛÎó¤òÊÖ¤¹
149    function getHiddenFileList() {
150        $cnt = 0;
151        foreach($this->keyname as $val) {
152            if($this->temp_file[$cnt] != "") {
153                $arrRet["temp_" . $val] = $this->temp_file[$cnt];
154            }
155            if($this->save_file[$cnt] != "") {
156                $arrRet["save_" . $val] = $this->save_file[$cnt];
157            }
158            $cnt++;
159        }
160        return $arrRet;
161    }
162   
163    // HIDDEN¤ÇÁ÷¤é¤ì¤Æ¤­¤¿¥Õ¥¡¥¤¥ë̾¤ò¼èÆÀ¤¹¤ë
164    function setHiddenFileList($arrPOST) {
165        $cnt = 0;
166        foreach($this->keyname as $val) {
167            $key = "temp_" . $val;
168            if($arrPOST[$key] != "") {
169                $this->temp_file[$cnt] = $arrPOST[$key];
170            }
171            $key = "save_" . $val;
172            if($arrPOST[$key] != "") {
173                $this->save_file[$cnt] = $arrPOST[$key];
174            }
175            $cnt++;
176        }
177    }
178   
179    // ¥Õ¥©¡¼¥à¤ËÅϤ¹ÍѤΥե¡¥¤¥ë¾ðÊóÇÛÎó¤òÊÖ¤¹
180    function getFormFileList($temp_url, $save_url) {
181        $cnt = 0;
182        foreach($this->keyname as $val) {
183            if($this->temp_file[$cnt] != "") {
184                // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¥Á¥§¥Ã¥¯(¥Ñ¥¹¤Î¥¹¥é¥Ã¥·¥å/¤¬Ï¢Â³¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£)
185                if(ereg("/$", $temp_url)) {
186                    $arrRet[$val]['filepath'] = $temp_url . $this->temp_file[$cnt];
187                } else {
188                    $arrRet[$val]['filepath'] = $temp_url . "/" . $this->temp_file[$cnt];
189                }
190            } elseif ($this->save_file[$cnt] != "") {
191                // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¥Á¥§¥Ã¥¯(¥Ñ¥¹¤Î¥¹¥é¥Ã¥·¥å/¤¬Ï¢Â³¤·¤Ê¤¤¤è¤¦¤Ë¤¹¤ë¡£)
192                if(ereg("/$", $save_url)) {
193                    $arrRet[$val]['filepath'] = $save_url . $this->save_file[$cnt];
194                } else {
195                    $arrRet[$val]['filepath'] = $save_url . "/" . $this->save_file[$cnt];
196                }
197            }
198            if($arrRet[$val]['filepath'] != "") {
199                // ¥Õ¥¡¥¤¥ë²£Éý
200                $arrRet[$val]['width'] = $this->width[$cnt];
201                // ¥Õ¥¡¥¤¥ë½ÄÉý
202                $arrRet[$val]['height'] = $this->height[$cnt];
203                // ɽ¼¨Ì¾
204                $arrRet[$val]['disp_name'] = $this->disp_name[$cnt];
205            }
206            $cnt++;
207        }
208        return $arrRet;
209    }
210   
211    // DBÊݸÍѤΥե¡¥¤¥ë̾ÇÛÎó¤òÊÖ¤¹
212    function getDBFileList() {
213        $cnt = 0;
214        foreach($this->keyname as $val) {
215            if($this->temp_file[$cnt] != "") {
216                $arrRet[$val] = $this->temp_file[$cnt];
217            } else  {
218                $arrRet[$val] = $this->save_file[$cnt];
219            }
220            $cnt++;
221        }
222        return $arrRet;
223    }
224   
225    // DB¤ÇÊݸ¤µ¤ì¤¿¥Õ¥¡¥¤¥ë̾ÇÛÎó¤ò¥»¥Ã¥È¤¹¤ë
226    function setDBFileList($arrVal) {
227        $cnt = 0;
228        foreach($this->keyname as $val) {
229            if($arrVal[$val] != "") {
230                $this->save_file[$cnt] = $arrVal[$val];
231            }
232            $cnt++;
233        }
234    }
235   
236    // ²èÁü¤ò¥»¥Ã¥È¤¹¤ë
237    function setDBImageList($arrVal) {
238        $cnt = 0;
239        foreach($this->keyname as $val) {
240            if($arrVal[$val] != "" && $val == 'tv_products_image') {
241                $this->save_file[$cnt] = $arrVal[$val];
242            }
243            $cnt++;
244        }
245    }
246   
247    // DB¾å¤Î¥Õ¥¡¥¤¥ë¤ÎÆâºï½üÍ׵᤬¤¢¤Ã¤¿¥Õ¥¡¥¤¥ë¤òºï½ü¤¹¤ë¡£
248    function deleteDBFile($arrVal) {
249        $objImage = new SC_Image($this->temp_dir);
250        $cnt = 0;
251        foreach($this->keyname as $val) {
252            if($arrVal[$val] != "") {
253                if($this->save_file[$cnt] == "" && !ereg("^sub/", $arrVal[$val])) {
254                    $objImage->deleteImage($arrVal[$val], $this->save_dir);
255                }
256            }
257            $cnt++;
258        }
259    }
260   
261    // ɬ¿ÜȽÄê
262    function checkEXISTS($keyname = "") {
263        $cnt = 0;
264        $arrRet = array();
265        foreach($this->keyname as $val) {
266            if($val == $keyname || $keyname == "") {
267                // ɬ¿Ü¤Ç¤¢¤ì¤Ð¥¨¥é¡¼¥Á¥§¥Ã¥¯
268                if ($this->necessary[$cnt] == true) {
269                    if($this->save_file[$cnt] == "" && $this->temp_file[$cnt] == "") {
270                        $arrRet[$val] = "¢¨ " . $this->disp_name[$cnt] . "¤¬¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤Æ¤¤¤Þ¤»¤ó¡£<br>";
271                    }
272                }
273            }
274            $cnt++;
275        }
276        return $arrRet;
277    }
278}
279?>
Note: See TracBrowser for help on using the repository browser.