I have an HTML form where I get uploaded files, in the case of an image and another with several files in PDF, I need to organize them by placing everything in a folder, for that I used mkdir, I was able to create a folder with the name that I get a variable, ie the name of the folder being created is a variable that takes content via POST from a form input, how do I play the files coming from the upload within that folder being created in the same code?
What's happening at the moment with my current code is: the files are placed in the same place where the folder is created but I can not put them inside it.
PHP code:
$vregistro = utf8_decode($_POST['f_registro']); //Guarda um nome digitado pelo usuário que será o nome da pasta criada
mkdir("C:\local\Arquivos\Documentos&Logos/$vregistro", 0777, true); //Cria a pasta no servidor com o nome guardado na variável
$uploaddir = 'C:\local\Arquivos\Documentos&Logos/'; //Arquivo fica no mesmo local da pasta criada porém fora dela
$uploadfile = $uploaddir . basename($_FILES['fanexo']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['fanexo']['tmp_name'], $uploadfile)) { //Upload de imagem que precisa ser guardado na pasta criada acima
echo "Arquivo válido e enviado com sucesso.\n";
}else{
echo "Upload ERROR <--\n";
}
echo 'Debug: ';
print_r($_FILES);
print "</pre>";
$total = count($_FILES['pdfanexo']['name']);
for($i=0; $i<$total; $i++) { //Upload de vários PDFS que precisa ser guardados na mesma pasta que a imagem no caso a pasta criada no inicio
$tmpFilePath = $_FILES['pdfanexo']['tmp_name'][$i];
if ($tmpFilePath != ""){
$newFilePath = "C:\local\Arquivos\Documentos&Logos/" . $_FILES['pdfanexo']['name'][$i];
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
}
}
}