Good evening.
I have the following php structure
<?php
require_once("testaAdmin.php");
require_once("../_global/_erros/erros.ini");
require_once("../_controlls/_util/Constantes.php");
$constantes = new Constantes();
if (isset($_POST["acao"]) && $_POST["acao"] == "cadastrar") {
......
function comparaArrays($array1, $array2)
{
if(is_array($array1) && count($array1) > 0) {
$i = 0;
foreach($array1 as $value1) {
foreach($array2["name"] as $key =>$value2) {
print $value2."<br>";
if ($value1 == $value2) {
if ( $array2["error"][$key] == 0) {
$extensao = pathinfo($value2, PATHINFO_EXTENSION);
$nomeFoto = md5(uniqid(time())).".". $extensao;
move_uploaded_file($array2["tmp_name"][$key], "../".$constantes->getEnderecoNormal()."/".$nomeFoto);
$fotosDao->cadastrar ($imoveisDao->ultimoIdCadastrado(), $nomeFoto);
}
$i++;
break;
}
}
}
}
}
$arquivos1 = explode ("|", $_POST["arquivos"]);
$arquivos2 = $_FILES["fotos"];
comparaArrays($arquivos1, $arquivos2);
.......
}
?>
I have the $constantes->getEnderecoNormal()
construct in the line of move_uploaded_file
that php returns me that the object does not exist if placed inside the function. But if placed outside the function it works.
Where is the error?
Role change as amended:
///////////////////////////UPLOAD DAS FOTOS////////////////////////////////////
function comparaArrays($array1, $array2, $imoveisDao, $constantes, $fotosDao, $ultimoIdCadastrado)
{
if(is_array($array1) && count($array1) > 0) {
$i = 0;
foreach($array1 as $value1) {
foreach($array2["name"] as $key =>$value2) {
if ($value1 == $value2) {
if ( $array2["error"][$key] == 0) {
$extensao = pathinfo($value2, PATHINFO_EXTENSION);
$nomeFoto = md5(uniqid(time())).".". $extensao;
move_uploaded_file($array2["tmp_name"][$key], "../".$constantes->getEnderecoNormal()."/".$nomeFoto);
$fotosDao->cadastrar ($ultimoIdCadastrado, $nomeFoto);
}
$i++;
break;
}
}
}
}
}
$arquivos1 = explode ("|", $_POST["arquivos"]);
$arquivos2 = $_FILES["fotos"];
comparaArrays($arquivos1, $arquivos2, $imoveisDao, $constantes, $fotosDao, $imoveisDao->ultimoIdCadastrado());
////////////////////////////UPLOAD DAS FOTOS////////////////////////////////////