[903] | 1 | <?php |
---|
| 2 | class upload |
---|
| 3 | { |
---|
| 4 | |
---|
| 5 | private $pathToSave; |
---|
| 6 | private $ArrayFiles; |
---|
| 7 | |
---|
| 8 | function __construct() |
---|
| 9 | { |
---|
| 10 | ini_set("session.save_path","/php_sessions"); |
---|
| 11 | $this->pathToSave = ini_get("session.save_path"); |
---|
| 12 | $this->ArrayFiles = array ( |
---|
| 13 | "server" => $_SERVER['SERVER_ADDR'], |
---|
| 14 | "path" => $_SESSION['phpgw_info']['instant_messenger']['path'], |
---|
| 15 | "filePhp" => "inc/class.download.inc.php?file=" |
---|
| 16 | ); |
---|
| 17 | |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | public function Load_file($Array_FILES) |
---|
| 21 | { |
---|
| 22 | |
---|
| 23 | $maxsize = ini_get('upload_max_filesize'); |
---|
| 24 | if (!is_numeric($maxsize)) { |
---|
| 25 | if (strpos($maxsize, 'M') !== false){ |
---|
| 26 | $maxsize = intval($maxsize)*1024*1024; |
---|
| 27 | }elseif (strpos($maxsize, 'K') !== false){ |
---|
| 28 | $maxsize = intval($maxsize)*1024; |
---|
| 29 | }elseif (strpos($maxsize, 'G') !== false){ |
---|
| 30 | $maxsize = intval($maxsize)*1024*1024*1024; |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | if ($Array_FILES['file']['name'] != '') { |
---|
| 35 | $tmp_name = $Array_FILES['file']['tmp_name']; |
---|
| 36 | $file = trim(md5(time()) . "_IM_SendFile_" . $Array_FILES['file']['name']); |
---|
| 37 | $this->ArrayFiles['fileUp'] = $file; |
---|
| 38 | unset ($_SESSION['instant_messenger']['fileIM']); |
---|
| 39 | |
---|
| 40 | $_SESSION['instant_messenger']['fileIM']['name_file'] = $file; |
---|
| 41 | $_SESSION['instant_messenger']['fileIM']['size_file'] = $Array_FILES['file']['size']; |
---|
| 42 | $_SESSION['instant_messenger']['fileIM']['ArrayServer'] = serialize($this->ArrayFiles); |
---|
| 43 | $this->upload_file($tmp_name, $file); |
---|
| 44 | } |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | public function upload_file($tmp_name, $file) |
---|
| 48 | { |
---|
| 49 | if (!move_uploaded_file($tmp_name, $this->pathToSave ."/". $file)) { |
---|
| 50 | echo "<script>alert('Erro no Upload!')</script>"; |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | public function size_file() |
---|
| 55 | { |
---|
| 56 | $Name_file = $_SESSION['instant_messenger']['fileIM']['name_file']; |
---|
| 57 | $Size_file = $_SESSION['instant_messenger']['fileIM']['size_file']; |
---|
| 58 | |
---|
| 59 | if (intval($Size_file / 1024) == intval(filesize($this->pathToSave ."/". $Name_file) / 1024)) { |
---|
| 60 | // ALEXANDRE CORREIA - MEIO XUNXXO |
---|
| 61 | //return "1-A : " . intval($Size_file / 1024). "---" ."U : " . intval(filesize($this->pathToSave.$Name_file) / 1024); |
---|
| 62 | return true; |
---|
| 63 | } else { |
---|
| 64 | // ALEXANDRE CORREIA - MEIO XUNXXO |
---|
| 65 | //return "2-A : " . intval($Size_file / 1024). "---" ."U : " . intval(filesize($this->pathToSave.$Name_file) / 1024); |
---|
| 66 | return false; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | public function name_file() |
---|
| 71 | { |
---|
| 72 | return base64_encode($_SESSION['instant_messenger']['fileIM']['ArrayServer']); |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | // Requisições via POST |
---|
| 77 | if (isset ($_POST['to'])) { |
---|
| 78 | $Obj_up = new upload(); |
---|
| 79 | $Obj_up->Load_file($_FILES); |
---|
| 80 | } |
---|
| 81 | ?> |
---|