2
I have the following code
$allowed = array('png', 'jpg', 'gif','zip');
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error"}';
exit;
}
else{
$nomesImagens = (isset($_COOKIE['nomesImagens'])) ? $_COOKIE['nomesImagens'] : '';
if (empty($nomesImagens)) {
setcookie("nomesImagens", $_FILES['upl']['name'], time()+300, "/");
}
else{
$novoNome = $_COOKIE['nomesImagens'].",".$nomesImagens;
setcookie("nomesImagens", $novoNome, time()+300, "/");
}
$tmpImagens = (isset($_COOKIE['tmpImagens'])) ? $_COOKIE['tmpImagens'] : '';
if (empty($tmpImagens)) {
setcookie("tmpImagens", $_FILES['upl']['tmp_name'], time()+300, "/");
}
else{
$novoNome = $_COOKIE['tmpImagens'].",".$tmpImagens;
setcookie("tmpImagens", $novoNome, time()+300, "/");
}
}
}
echo '{"status":"error"}';
exit;
With each selected image it preloads the image and stores the tmp_name and the name of the image in cookies through an ajax request, but when inserting the whole form, the input files disappear so I have to enter by the cookies I have already recorded, it inserts into the database but does not allocate the images, it is possible to do this with temporary files?
Not that I know of. You can upload to a temporary folder. Then you take the image and delete everything.
– Diego Souza
Do you have any idea how it can be done ?
– Felipe Duarte
It depends on your application. Just upload the image in a temporary folder with the name of the image. Then you take it later when you upload. Make the copy of the image in the correct folder and delete from the temporary folder.
– Diego Souza
I’ll really have to do it, put it as an answer to get more organized
– Felipe Duarte