I have to make a PHP script that sends a single upado file to multiple folders (listed in the root of the server dynamically). The problem is that the first upload is done without problems, then I can not send it to the other folders.
EXEMPLO:
$dir = $_SERVER["DOCUMENT_ROOT"];
$scandir = scandir($dir);
$pastas = array();
foreach ($scandir as $pasta) {
if($pasta == "." || $pasta == ".." || $pasta == ".htaccess" || $pasta == "default.htmlx" || $pasta == "error_log") {
} else {
$pastas[] = $pasta;
}
}
if(isset($_POST['upload'])) {
foreach ($pastas as $key => $pasta) {
$arquivo = $_FILES['file']['name'];
$file_tmp =$_FILES['file']['tmp_name'];
$desired_dir = $dir."/".$pasta."/sistema/engine/";
$caminho = $desired_dir.$arquivo;
$upload = move_uploaded_file($file_tmp, $caminho);
if(!$upload) {
echo "Erro ao realizar upload em: ".$caminho;
exit(0);
}
}
echo "Deu certo.";
exit(0);
}
Does anyone know where I might be going wrong or if there is any upload restriction in foreach?