MkFramework
 All Data Structures Functions
plugin_upload.php
1 <?php
2 /*
3 This file is part of Mkframework.
4 
5 Mkframework is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License.
8 
9 Mkframework is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13 
14 You should have received a copy of the GNU Lesser General Public License
15 along with Mkframework. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
24 
25  private $tFile;
26  private $sOriginFileName;
27  private $sTmpFileName;
28  private $sNewPath;
29  private $sExtension;
30  private $bValid;
31  private $salt='1EE7a89';
32 
38  public function __construct($sColumn){
39  if(isset($_FILES[$sColumn]) && $_FILES[$sColumn]['size'] > 0){
40  $this->bValid=true;
41  $this->tFile=$_FILES[$sColumn];
42  $this->sOriginFileName=basename($_FILES[$sColumn]['name']);
43  $this->sTmpFileName=$_FILES[$sColumn]['tmp_name'];
44  $this->loadExtension();
45  }else{
46  $this->bValid=false;
47  }
48  }
49 
56  public function saveAs($sNewFileName){
57  $this->sNewPath=$sNewFileName.sha1($this->salt.$sNewFileName).'.'.time().'.'.$this->sExtension;
58 
59  if(move_uploaded_file($this->sTmpFileName, $this->sNewPath)){
60  return true;
61  }
62  else{
63  return false;
64  }
65  }
71  public function getPath(){
72  return $this->sNewPath;
73  }
79  public function isValid(){
80  return $this->bValid;
81  }
82 
83  private function loadExtension(){
84  $tFileName=preg_split('/\./',$this->sOriginFileName);
85  $this->sExtension= end($tFileName);
86  }
87 
88 }
__construct($sColumn)
saveAs($sNewFileName)