0
I got this image upload code to work on Postgresql, but I would like to change it to work on phpMyAdmin, but I’m encountering a certain difficulty, and I would like to count on the help of friends.
The code goes like this:
//Instancia a clase passando o arquivo (atributo name no form).
$logo = "";
if (isset($_FILES["logo"]))
{
$dir_dest = "../upload";
$upload = new Upload($_FILES['logo'], $dir_dest);
// verifica se foi realizado corretamente o Upload
if ($upload->processed){
$logo = $upload->file_dst_name;
}
}
$objImagemlogo = new Imagemlogo();
$objImagemlogo->codigo = $_POST["codigo"];
$objImagemlogo->logo = $logo;
$objImagemlogo->atualizar();
?>
The name in the upload file is Upload.php.
I tried to do the following:
<form name="enter" method="post" action="Upload.php" enctype="multipart/form-data">
<label>Código:</label></br>
<input type="number" name="codigo" value="<?php echo $res['codigo'];?>" readonly="readonly"></br>
<label>Imagem Atual:</label></br>
<img width="200" height="auto" src="../upload/<?php echo $res['logo'];?>"/></br>
<label>Imagem:</label></br>
<input type="file" name="logo" ></br>
<input class="input" type="submit" name="enter" value="Atualizar" /></br>
</form>
I thought that bringing the Upload.php file in the action would work, but I was wrong. And now I have no idea how to change the code so that it can work in the Mysql project.
If friends can help me out, I’d be grateful.
Hugs to all, and BRAWL from now on.
As requested below follows all contents of the query file of the objImagemlogo:
<?php
include_once 'BD.class.php';
class Imagemlogo {
private $codigo;
private $logo;
//variaveis internas
private $bd; //conexão com o banco
private $tabela; //nome da tabela
public function __construct() {
$this->bd = new BD();
$this->tabela = "pagcabecalho";
}
public function __destruct() {
unset($this->bd);
}
public function __get($key) {
return $this->$key;
}
//método de retorno de valores do objeto
public function __set($key, $value) {
$this->$key = $value;
}
public function listar($complemento = "") {
$sql = "SELECT * FROM $this->tabela ".
$complemento;
$resultado = pg_query($sql);
$retorno = NULL;
//percorre os registros
while ($reg = pg_fetch_assoc($resultado)) {
//transforma em objetos produto
$obj = new Imagemlogo();
$obj->codigo = $reg["codigo"];
$obj->logo = $reg["logo"];
//adiciona a variavel de retorno
$retorno[] = $obj;
}
return $retorno;
}
public function excluir() {
$sql = "delete from $this->tabela where codigo=$this->codigo";
$retorno = pg_query($sql);
return $retorno;
}
public function retornarunico() {
$sql = "Select * FROM $this->tabela where codigo=$this->codigo LIMIT 1";
$resultado = pg_query($sql);
$retorno = NULL;
$req = pg_fetch_assoc($resultado);
if ($req == true) {
$obj = new Imagemlogo();
$obj->codigo = $req["codigo"];
$obj->logo = $req["logo"];
$retorno = $obj;
} else {
$retorno = null;
}
return $retorno;
}
public function atualizar() {
$retorno = false;
$sql = "UPDATE $this->tabela SET logo='$this->logo' WHERE codigo=$this->codigo";
$retorno = pg_query($sql);
return $retorno;
}
}
?>
You need to change your query, the upload remains the same thing, could post the query that the object
$objImagemlogo
executes?– Jeferson Assis
Hi Jeferson Assis, I edited the message with the file data that refers to the upload. I hope that’s what you want! Thanks in advance for your attention.
– Murilo Cabral
You need to change the connection and the functions you refer to in the sample database:
pg_query
,pg_fetch_assoc
, among the others– Jeferson Assis
Thanks Jeferson Assis, but I have no idea how to make such changes, you could give me a light, because I am layman in this type of file, but very curious. Hugs...
– Murilo Cabral