2
I’m uploading an image with an object-oriented paradigm and I’m making a strange mistake:
The upload is done successfully, the image is displayed normally on the site. Everything normal.
But when I go in the folder I saved the images, although they are there, windows explorer does not show the thumbnail, only shows that the image is there and with its normal properties.
By doing a test, I tried to compress them into . zip but Winrar from the compression error. What might be?
Permission 777 in folder
<?php
class Upload {
private $nome;
private $nomeBanco;
private $nomeTemporario;
private $largura;
private $altura;
private $tamanho;
private $endereco;
private $extensao;
public function __construct ($_file, $_url) {
$dimensoes = getimagesize($_file["tmp_name"]);
$this->extensao = pathinfo($_file["name"], PATHINFO_EXTENSION);
$this->nome = $_file["name"];
$this->nomeBanco = $this->setNomeBanco();
$this->nomeTemporario = $_file["tmp_name"];
$this->largura = $dimensoes[0];
$this->altura = $dimensoes[1];
$this->tamanho = $_file["size"];
$this->endereco = $_url;
}
public function setNomeBanco () {
return md5(uniqid(time())).".". $this->extensao;
}
public function getNome() {
return $this->nome;
}
public function getNomeBanco() {
return $this->nomeBanco;
}
public function getNomeTemporario() {
return $this->nomeTemporario;
}
public function getLargura() {
return $this->largura;
}
public function getAltura() {
return $this->altura;
}
public function getTamanho() {
return $this->tamanho;
}
public function getEndereco() {
return $this->endereco;
}
public function getExtensao() {
return $this->extensao;
}
}
?>
<?php
class UploadDao {
private $arquivo;
public function __construct($_upload) {
$this->arquivo = $_upload;
}
/*
Erros do arquivo;
erro ($_tamanho)
Onde $_tamanho é em bits, ou seja, 5MB - 5 * 1024 * 1024=
*/
public function erro ($_tamanho) {
$mensagem = "Sem erros!";
$erro = 0;
if(isset($this->arquivo)) {
if (
$this->arquivo->getExtensao() != "JPG" &&
$this->arquivo->getExtensao() != "jpg" &&
$this->arquivo->getExtensao() != "JPEG" &&
$this->arquivo->getExtensao() != "jpeg" &&
$this->arquivo->getExtensao() != "PNG" &&
$this->arquivo->getExtensao() != "png"
) {
$mensagem = "Imagem precisa ser nos formatos: jpg, JPG, jpeg, JPEG, png, PNG";
$erro = 1;
} else if ($this->arquivo->getTamanho() >= $_tamanho ) {
$mensagem = "Tamanho máximo da Imagem é de ".($_tamanho/(1024*1024))." MB";
$erro = 2;
}
}
return array($erro, $mensagem, $this->arquivo->getTamanho()/(1024*1024));
}
public function uploadFile() {
$erro = 0;
$mensagem = "Sucesso";
try {
$urlEnvio = $this->arquivo->getEndereco()."/".$this->arquivo->getNomeBanco();
move_uploaded_file($this->arquivo->getNomeTemporario(), $urlEnvio);
} catch (Exception $e) {
$erro = 1;
$mensagem = "falha no envio";
}
return array($erro, $mensagem);
}
private function geraMiniatura ($_largura, $_url) {
//CRIA UMA NOVA IMAGEM
if( $this->arquivo->getExtensao() == "JPG" || $this->arquivo->getExtensao() == "jpg" ) {
$imagem_orig = ImageCreateFromJPEG($this->arquivo->getNomeTemporario());
} else if( $this->arquivo->getExtensao() == "JPEG" || $this->arquivo->getExtensao() == "jpeg") {
$imagem_orig = ImageCreateFromJPEG($this->arquivo->getNomeTemporario());
} else if( $this->arquivo->getExtensao() == "PNG" || $this->arquivo->getExtensao() == "png") {
$imagem_orig = ImageCreateFromPNG($this->arquivo->getNomeTemporario());
}
//LARGURA
$pontoX = ImagesX($imagem_orig);
//ALTURA
$pontoY = ImagesY($imagem_orig);
//DEFINE OS PARÂMETROS DA MINIATURA
$largura = $_largura;
$altura = ($pontoY * $largura) / $pontoX;
//CRIA O THUMBNAIL
$imagem_fin = ImageCreateTrueColor($largura, $altura);
//COPIA A IMAGEM ORIGINAL PARA DENTRO
ImageCopyResampled($imagem_fin, $imagem_orig, 0, 0, 0, 0, $largura+1, $altura+1, $pontoX, $pontoY);
//SALVA A IMAGEM
ImageJPEG($imagem_fin, $_url,100);
//LIBERA A MEMÓRIA
ImageDestroy($imagem_orig);
ImageDestroy($imagem_fin);
}
}
?>
You can open it with an image editor?
– Marco Giovanni
No. The editor couldn’t open
– Carlos Rocha
The image size is 0 Kb?
– Marco Giovanni
Neither Windows Fax Viewer nor Photoshop CS6
– Carlos Rocha
230kb. On the page image is being displayed normally. You can even apply zoom plugin
– Carlos Rocha
I tried to attach the image here in question but gave that I do not have permission for it. Contact the administrator. But this with 777.
– Carlos Rocha
What system are you using? Linux or Windows?
– Marco Giovanni
Windows. The strange thing is that I copied the images out of the server and opened it normally. Another problem is that in the same directory, I have 3 image folders. And only this giving this error in this specific folder. I’m thinking that the problem is being caused at the time of upload. I posted in the question the code I’m using.
– Carlos Rocha
You tried to set the permissions by going to the direct button in the folder, Properties -> Security -> Advanced -> Add -> Select a security entity -> Type "All", and set full control to "All"?
– Marco Giovanni
just like that
– Carlos Rocha
In addition to Carlos' tips, try adding your user as the owner of the whole folder and its subitens. This is clearly windows permission error, since on the web, as you say, is working normally
– Bruno Pitteli Gonçalves