file_check_just_pdf.php
3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* i-Educar - Sistema de gestão escolar
*
* Copyright (C) 2006 Prefeitura Municipal de ItajaÃ
* <ctima@itajai.sc.gov.br>
*
* Este programa é software livre; você pode redistribuÃ-lo e/ou modificá-lo
* sob os termos da Licença Pública Geral GNU conforme publicada pela Free
* Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
* qualquer versão posterior.
*
* Este programa é distribuÃÂdo na expectativa de que seja útil, porém, SEM
* NENHUMA GARANTIA; nem mesmo a garantia implÃÂcita de COMERCIABILIDADE OU
* ADEQUAÃÃO A UMA FINALIDADE ESPECÃFICA. Consulte a Licença Pública Geral
* do GNU para mais detalhes.
*
* Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
* com este programa; se não, escreva para a Free Software Foundation, Inc., no
* endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
*
* @author Paula Bonot <bonot@portabilis.com.br>
* @category i-Educar
* @license @@license@@
* @package Api
* @subpackage Modules
* @since Arquivo disponÃvel desde a versão ?
* @version $Id$
*/
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;
class FileController {
var $file;
var $errorMessage;
var $maxSize;
var $suportedExtensions;
function __construct($file, $maxSize = NULL,
$suportedExtensions = NULL){
$this->file = $file;
if ($maxSize!=null)
$this->maxSize = $maxSize;
else
$this->maxSize = 2048*1024;
if ($suportedExtensions != null)
$this->suportedExtensions = $suportedExtensions;
else
$this->suportedExtensions = array('pdf');
}
function sendFile(){
$tmp = $this->file["tmp_name"];
$tenant = config('legacy.app.database.dbname');
$file = new File($tmp);
if (Storage::put($tenant, $file, 'public')) {
return Storage::url($file->hashName($tenant));
} else {
$this->errorMessage = "Ocorreu um erro no servidor ao enviar foto. Tente novamente.";
return '';
}
}
function validateFile(){
$msg='';
$name = $this->file["name"];
$size = $this->file["size"];
$ext = $this->getExtension($name);
if(strlen($name) > 0)
{
// File format validation
if(in_array($ext,$this->suportedExtensions))
{
// File size validation
if($size < $this->maxSize){
return true;
}
else{
$this->errorMessage = "Não são permitidos arquivos com mais de 2MB.";
return false;
}
}
else{
$this->errorMessage = "Deve ser enviado um arquivo do tipo pdf.";
return false;
}
}
else{
$this->errorMessage = "Selecione um arquivo.";
return false;
}
$this->errorMessage = "Arquivo inválido.";
return false;
}
function getErrorMessage(){
return $this->errorMessage;
}
function getExtension($name)
{
$i = strrpos($name,".");
if (!$i)
return "";
$l = strlen($name) - $i;
$ext = substr($name,$i+1,$l);
return $ext;
}
}
?>