✏️ 正在编辑: Upload.php
路径:
/srv/systems_dir/contemax/library/Core/Upload.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_Upload { public $model; public $upload; public $diretorio; public $tmpName; public $extensions; public $anexo = false; public $erro; public function __construct($model, $extensions = array('jpg', 'png', 'jpeg', 'gif', 'pdf', 'zip', 'rar')) { $this->upload = new Zend_File_Transfer_Adapter_Http(); if( !$this->upload->isValid() ) { $this->upload = false; return false; } $this->model = $model; $this->extensions = $extensions; $this->upload->addValidator('Extension', false, $this->extensions); if( !$this->upload->isValid() ) { $this->erro = 'Extensão de arquivo não liberada.'; return false; } return true; } public function upload($name){ $this->diretorio = $this->model->createDirectory(); $fileInfo = $this->upload->getFileInfo(); $extensao = pathinfo($fileInfo[$name]['name'], PATHINFO_EXTENSION); $fname = md5(microtime()); $this->fileName = "$fname.$extensao"; $this->tmpName = $fileInfo[$name]['tmp_name']; if(in_array($extensao, array('jpg', 'png', 'jpeg', 'gif'))){ $this->uploadImage($this->upload); } $this->upload->setDestination($this->diretorio); $this->upload->addFilter('Rename', $this->fileName); $anexo = $this->upload->receive() ? $this->fileName : false; if(in_array($extensao, array('pfx'))){ $anexo = $this->gerarCertificadoPem(); } $this->anexo = $anexo; if (!$anexo) { $this->erro = "Algum erro ocorreu ao anexar o arquivo."; return false; } return true; } public function uploadImage($upload){ $fileSize = $upload->getFileSize(); if (floatval($fileSize) > 500) { $imagem = file_get_contents($this->tmpName); $anexo = $this->reduce($imagem, $this->diretorio, $this->fileName); $this->anexo = $anexo; if (!$anexo) { $this->erro = "Algum erro ocorreu ao anexar o arquivo."; return false; } return true; } } public function reduce($contents, $dir, $fileName) { $original = imagecreatefromstring($contents); $width = imagesx($original); $height = imagesy($original); $newWidth = $width < 1000 ? $width : 1000; $newHeight = floor($height * ($newWidth / $width)); $thumb = imagecreatetruecolor($newWidth, $newHeight); imagecopyresized($thumb, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); header("Content-type: image/jpeg"); $result = imagejpeg($thumb, "$dir/$fileName"); return $result ? $fileName : $result; } }
💾 保存文件
← 返回文件管理器