- Output for git.master, git.master_jit, rfc.property-hooks
- <?
/*
Tipo : classe
Nome : UpLoad
Data : 29/08/2003
Autor: Wonder Alexandre Luz Alves
Desc : esta class faz upload de arquivo gera uma mini imagem p/ visualização e tem tratamento de erros
Versão: 1.2
*/
class UpLoad
{
var $arquivo_permissao;
var $dir;
var $max_filesize;
var $idioma;
var $error=0;
var $file_type;
var $file_name;
var $file_size;
var $arquivo;
var $file_path;
var $warning=0;
var $MINI_name;
var $MINI_path="images_mini";
function UpLoad ($permissao="" , $max_file = 300000, $dir = "images",$idioma="portugues"){
if ( empty ($permissao) ) $permissao = array ("image/pjpeg","image/x-png","image/jpeg","image/png","image/gif");
$this->arquivo_permissao = $permissao;
$this->max_filesize = $max_file;
$this->dir = $dir;
$this->idioma = $idioma;
}
function putFile ($file){
$this->file_type = strtok ( $_FILES[$file]['type'], ";");
$this->file_name = $_FILES[$file]['name'];
$this->file_size = $_FILES[$file]['size'];
$this->temp = $_FILES[$file]['tmp_name']; // upload para o diretorio temp
if(!in_array($this->file_type, $this->arquivo_permissao))
$this->Error(1);
if ( ($this->file_size <= 0) || ($this->file_size > $this->max_filesize) ) $this->Error(2);
if ($this->error == ""){
$filename = basename ($this->file_name);
if (!empty ($this->dir) )
$this->arquivo = $this->dir."/".$filename;
else
$this->arquivo = $filename;
if (file_exists($this->arquivo)){
srand((double)microtime()*1000000);
$filename = rand(0,20000).$filename;
if (!empty ($this->dir))
$this->arquivo = $this->dir."/".$filename;
else
$this->arquivo = $filename;
}
if(!is_uploaded_file($this->temp)) $this->Error(3);
if(!@move_uploaded_file($this->temp,$this->arquivo) ) $this->Error(4);
return $this->arquivo;
}
else {
return false;
}
}
function checar_gd()
{
$testGD = get_extension_funcs("gd");
if (!$testGD)
$this->error(5);
else{
ob_start();
phpinfo(8);
$grab = ob_get_contents();
ob_end_clean();
$version = strpos ($grab,"2.0 or higher");
if ( $version ) return "gd2";
else return "gd";
}
}
function Gerar_mini($new_image_file_path, $max_width=480, $max_height=1600 )
{
$return_val = 1;
if(eregi("\.png$",$this->arquivo)){
$return_val = ( ($img = ImageCreateFromPNG ( $this->arquivo )) && $return_val == 1 ) ? "1" : "0";
}
if(eregi("\.(jpg|jpeg)$",$this->arquivo)){
$return_val = ( ($img = ImageCreateFromJPEG ( $this->arquivo )) && $return_val == 1 ) ? "1" : "0";
}
if(eregi("\.gif$",$this->arquivo)){
$return_val = ( ($img = ImageCreateFromGif ( $this->arquivo )) && $return_val == 1 ) ? "1" : "0";
}
$FullImage_width = imagesx ($img);
$FullImage_height = imagesy ($img);
$ratio = ( $FullImage_width > $max_width ) ? (real)($max_width / $FullImage_width) : 1 ;
$new_width = ((int)($FullImage_width * $ratio)); //full-size width
$new_height = ((int)($FullImage_height * $ratio)); //full-size height
$ratio = ( $new_height > $max_height ) ? (real)($max_height / $new_height) : 1 ;
$new_width = ((int)($new_width * $ratio)); //mid-size width
$new_height = ((int)($new_height * $ratio)); //mid-size height
if ( $new_width == $FullImage_width && $new_height == $FullImage_height ) copy ( $this->arquivo, $new_image_file_path );
$gd_version = $this->checar_gd();
if ( $gd_version == "gd2" ) {
$full_id = ImageCreateTrueColor ( $new_width , $new_height ); //Crea un'immagine
ImageCopyResampled ( $full_id, $img, 0,0,0,0, $new_width, $new_height, $FullImage_width, $FullImage_height );
}
elseif ( $gd_version == "gd" ){
$full_id = ImageCreate ( $new_width , $new_height ); //Crea un'immagine
ImageCopyResized ( $full_id, $img, 0,0,0,0, $new_width, $new_height, $FullImage_width, $FullImage_height );
}
else $this->Error(5);
if(eregi("\.(jpg|jpeg)$",$this->arquivo)){
$return_val = ( $full = ImageJPEG( $full_id, $new_image_file_path, 80 ) && $return_val == 1 ) ? "1" : "0";
}
if(eregi("\.png$",$this->arquivo)) {
$return_val = ( $full = ImagePNG( $full_id, $new_image_file_path ) && $return_val == 1 ) ? "1" : "0";
}
if(eregi("\.gif$",$this->arquivo)) {
if($gd_version != "gd2")
return 0;
$return_val = ( $full = imagegif($full_id, $new_image_file_path) && $return_val == 1 ) ? "1" : "0";
}
ImageDestroy( $full_id );
return ($return_val) ? TRUE : FALSE ;
}
function Miniatura($larg=80, $alt=80, $pre_name="MINI_"){
if ((eregi("\.png$", $this->arquivo) || eregi("\.(jpg|jpeg)$", $this->arquivo) || eregi("\.gif$", $this->arquivo)) && $this->arquivo){
$this->MINI_name = $pre_name . $this->file_name;
if (!empty ($this->MINI_path))
$thumb_path = $this->MINI_path ."/". $pre_name . $this->file_name;
else
$thumb_path = $pre_name . $this->file_name;
if ($this->Gerar_mini($thumb_path, $larg, $alt))
return $thumb_path;
else{
$this->Warning(1);
return 0;
}
}
else $this->Warning(2);
}
function Error($op){
if($this->idioma="portugues"){
switch ($op){
case 0: return; break;
case 1: $this->error = "Error 1: Este tipo de arquivo não tem permissão para upload : $this->file_type."; break;
case 2: $this->error = "Error 2: Erro no tamanho do arquivo: $this->file_size Kb. Tamanho Maximo é $this->max_filesize."; break;
case 3: $this->error = "Error 3: Ocorreu um erro na transferencia do arquivo: $this->file_name."; break;
case 4: $this->error = "Error 4: Ocorreu um erro na transferencia de $this->temp para $this->file_name."; break;
case 5: $this->error = "Error 5: Biblioteca GD não instalada!";break;
}
}
?> <SCRIPT> alert("
Fatal error: Uncaught Error: Using $this when not in object context in /in/FOZ8G:174
Stack trace:
#0 {main}
thrown in /in/FOZ8G on line 174
Process exited with code 255.
This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.
Active branches
Archived branches
Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page
- 2020-03-21 RFC: Is_Literal - declined
- 2020-12-04 Enumerations - included in PHP 8.1
- 2018-06-15 Typed Properties v2 - implemented in PHP 7.4
- 2016-08-12 Object typehint - included in PHP 7.2
- 2016-08-14 Arrow functions - withdrawn
- 2016-05-29 array_change_keys() - withdrawn
- 2016-04-19 Lexical scope support for anonymous classes - suspended
- 2016-04-17 Functional Interfaces - declined
- 2016-03-16 Typed Properties - superseded in favor of Typed Properties 2.0
- 2015-08-27 Callable Prototypes - declined
- 2015-05-01 Short Closures - declined / withdrawn in favor of Arrow Functions
- 2015-02-18 Scalar type hints v5 - included in PHP 7
- 2015-02-14 Union Types - declined
- 2013-09-22 Anonymous classes - included in PHP 7