0
good night.
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 building $constantes->getEnderecoNormal()
on the line of move_uploaded_file
php returns that the object does not exist if placed inside the function. But if placed outside the function it works.
Where is the error?
Change of function 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////////////////////////////////////
Several other languages besides PHP allow, such as C++, Harbour, and when well used, it’s great. The question problem is related to a programming error only. There is nothing wrong with using each paradigm where it is best. I agree with your "I particularly like it as long as it’s done right". The problem is that usually the staff has a very closed head to get out of the "reins" of the institution/course/influence where learned, so do not mix paradigm pq is "sin" kkk.
– Bacco
@Bacco put a few quotes on "only PHP" because we are talking about it in this topic, it was more a poetic license in the text than in fact only she do it, as for example I can mention the Javascript that makes this tbm mixture and I love it too. And I don’t think it’s wrong to use as long as I know what’s going on.
– SK15
Well, I have added to the body of the question the new structure of the function and I would like to know your opinion on the amendment
– Carlos Rocha
Well the point is that you are mixing object-oriented programming with structured programming (magic that "only PHP" allows and is harshly criticized That’s news to me.
– durtto
It’s because that function only fits that context and it’s just her in that situation. If I put it inside a class of utilities for example, it will not be able to be used because its development is very peculiar. But you did. Thank you!
– Carlos Rocha
Carlos, has your problem been solved? If so, define it as a better answer and avoid others wasting time trying to answer! As for the question of own opinions without foundations in studies, in the programming I advise to avoid to the maximum, seeing that the best is to know how to use each tool/ method in its hour.
– Jhonny Mesquita