vini_loock Posted August 6, 2011 Report Share Posted August 6, 2011 (edited) <?php /*----------------------------------------------------------------------------------------------------// //----------------------------Class de tratamento de arquivos - PHP-----------------------------------// //----------------------------------------------------------------------------------------------------// //-----Todos os direitos reservados - Vinicius Siuta Borges-------------------------------------------// //-----Contato: viniciussiutaborges@hotmail.com-------------------------------------------------------// //--------||--: viniciussiutaborges@gmail.com---------------------------------------------------------// //----------------------------------------------------------------------------------------------------*/ class Files{ private $file, $file_ext, $file_name, $file_dir; private $ext_validas = array('jpg', 'png', 'gif', 'bmp', 'rar', 'zip', 'wma'); private $upload_dir = 'temp', $temp_dir = 'temp'; public function __construct($file = ''){ if($file != '')$this->start($file); } private function start($file = ''){ $this->file = $file; $info = pathinfo($file); $this->file_name = $info['filename']; $this->file_ext = $info['extension']; $this->file_dir = str_replace($this->file_name.'.'.$this->file_ext, '', $this->file); } public function setFile($file){ $this->start($file); } public function getFile(){ return $this->file; } public function setExt($ext = array('zip')){ $this->ext_validas = $ext; } public function getExt(){ return $this->ext_validas; } public function setUploadDir($dir){ $this->upload_dir = $dir; } public function getUploadDir(){ return $this->upload_dir; } public function setTempDir($dir){ $this->temp_dir = $dir; } public function getTempDir(){ return $this->temp_dir; } public function copy($old, $new){ if(copy($old, $new)){ return true; } return false; } public function move($old, $new){ if(rename($old, $new)){ return true; } return false; } public function upload($file){ $pre_name = date('YmdHis').rand(0, 999); move_uploaded_file($file['tmp_name'], $this->temp_dir.'/'.$pre_name.$file['name']); $this->start($this->temp_dir.'/'.$pre_name.$file['name']); if($this->valida()){ $this->move($this->file, $this->upload_dir.'/'.$pre_name.$file['name']); $this->start($this->upload_dir.'/'.$pre_name.$file['name']); }else{ $this->delete(); } } public function delete(){ if(file_exists($this->file) && unlink($this->file)){ return true; } return false; } public function valida(){ if(in_array($this->file_ext, $this->ext_validas)){ return true; } return false; } } ?> Edited August 6, 2011 by vini_loock Quote Link to comment Share on other sites More sharing options...
Question
vini_loock
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.