1
I have an HTML form where I receive files by upload, in case one of image and the other with several PDF files, I need to organize them putting everything in a folder, for that I used mkdir, I managed to create a folder with the name I receive from 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 inside that folder being created in the same code?
What is happening at the moment with my current code is: the files are placed in the same place where the folder is created but I cannot place 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)) {
}
}
}
just take the name of the folder you created and put it in the path
$uploaddir = 'C:\local\Arquivos\Documentos&Logos/'.$vregistro;
– Rafael Augusto
Doing this it continues the same way, just puts the name that is stored in $vregistro in the upload files.
– HBretone