Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Amigos, por favor, já tentei diversas funções, todas funcionam perfeitamente na rede local, mas nenhuma faz o Up quando os arquivos estão na internet!
Vou postar minha ultima tentativa aqui...
index23.php
<?php
require_once "class_upload.php";
$upload = new Upload();
$upload->Envia_Arquivo();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<title>Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="index23.php" method="post" enctype="multipart/form-data" name="form1">
<input type="file" name="arquivo">
<input type="submit" name="Submit" value="Enviar">
</form>
</body>
</html>
class_upload.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
set_time_limit(0);
include "funcoes23.php"; var $arquivo = "";
var $erro = array ( "0" => "upload execultado com sucesso!",
"1" => "O arquivo é maior que o permitido pelo Servidor",
"2" => "O arquivo é maior que o permitido pelo formulario",
"3" => "O upload do arquivo foi feito parcialmente",
"4" => "Não foi feito o upload do arquivo"
);
function Verifica_Upload()
{
$this->arquivo = isset($_FILES['arquivo']) ? $_FILES['arquivo'] : FALSE;
if(!is_uploaded_file($this->arquivo['tmp_name'])) {
return false;
}
$get = getimagesize($this->arquivo['tmp_name']);
if($get["mime"] != "image/jpeg")
{
echo "<span style=\"color: white; border: solid 1px; background: red;\">Esse foto nao é uma imagem valida</span>";
exit;
}
return true;
}
function Envia_Arquivo()
{
if($this->Verifica_Upload()) {
$this->gera_fotos();
return true;
} else {
echo "<span style=\"color: white; border: solid 1px; background: red;\">".$this->erro[$this->arquivo['error']]."</span>";
}
}
function gera_fotos()
{
$diretorio = "imagensNews/";
if(!file_exists($diretorio))
{
mkdir($diretorio);
}
$nome_foto = "imagem_".time().".jpg";
$nome_thumb = "thumb_".time().".jpg";
//determino uma resolução maxima e se a imagem for maior ela sera reduzida
reduz_imagem($this->arquivo['tmp_name'], 400, 300, $diretorio.$nome_foto);
//passo o tamanho da thumbnail
reduz_imagem($this->arquivo['tmp_name'], 120, 90, $diretorio.$nome_thumb);
echo "<span style=\"color: white; border: solid 1px; background: blue;\">".$this->erro[$this->arquivo['error']]."</span>";
}
}
?>
</body>
</html><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php//pega o tamanho da imagem ($original_x, $original_y)
list($width, $height) = getimagesize($img);
$original_x = $width;
$original_y = $height;
// se a largura for maior que altura
if($original_x > $original_y) {
$porcentagem = (100 * $max_x) / $original_x;
} $porcentagem = (100 * $max_y) / $original_y;
}
$tamanho_x = $original_x * ($porcentagem / 100);
$tamanho_y = $original_y * ($porcentagem / 100);
$image_p = imagecreatetruecolor($tamanho_x, $tamanho_y);
$image = imagecreatefromjpeg($img);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tamanho_x, $tamanho_y, $width, $height);
return imagejpeg($image_p, $nome_foto, 100);
}
?>
</body>
</html>
Obrigado!
Carregando comentários...