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

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