0
I’m doing 12 uploads on the same page and I’m using a code donkey, because I’m repeating myself. But I don’t know how to make the loop.
But this is not the problem. The case is that it is only working for the first four fields, being empty or not.
Here’s the code:
if (isset($_POST['idCliente'])) {
$idCliente = $_POST['idCliente'];
// echo $idCliente;
$uploaddir = 'assets/clientes/docs/';
$contratoSocial = $_FILES['ContratoSocial'];
$cnpj = $_FILES['cnpj'];
$InscricaoEstadual = $_FILES['InscricaoEstadual'];
$InscricaoMunicipal = $_FILES['InscricaoMunicipal'];
$ComprovanteEndereco = $_FILES['ComprovanteEndereco'];
$agefip = $_FILES['agefip'];
$rg = $_FILES['rg'];
$cpf = $_FILES['cpf'];
$comprovantereisdencia = $_FILES['comprovantereisdencia'];
$certidaonascimento = $_FILES['certidaonascimento'];
$certidaocasamento = $_FILES['certidaocasamento'];
/* DOCUMENTOS OBRIGATÓRIOS PARA EMPRESA
1 Contrato Social
2 Cartão CNPJ
3 Inscrição Estadual
4 Inscrição Municipal
5 Comprovante de Endereço da Empresa
6 AGEFIP
*/
/* DOCUMENTOS OBRIGATÓRIOS PARA VIDA
8 R.G.
9 C.P.F.
10 Comprovante de Residência
11 Certidão de Nascimento
12 Certidão de Casamento
*/
if($contratoSocial != ''){
$uploadfile = $uploaddir . basename($_FILES['ContratoSocial']['name']);
move_uploaded_file($_FILES['ContratoSocial']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '1';
$sql_contratoSocial = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_contratoSocial) or die(mysql_error());
}
if($cnpj !=''){
$uploadfile = $uploaddir . basename($_FILES['cnpj']['name']);
move_uploaded_file($_FILES['cnpj']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '2';
$sql_cnpj = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_cnpj) or die(mysql_error());
}
if($InscricaoEstadual !=''){
$uploadfile = $uploaddir . basename($_FILES['InscricaoEstadual']['name']);
move_uploaded_file($_FILES['InscricaoEstadual']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '3';
$sql_InscricaoEstadual = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_InscricaoEstadual) or die(mysql_error());
}
if($InscricaoMunicipal != ''){
$uploadfile = $uploaddir . basename($_FILES['InscricaoMunicipal']['name']);
move_uploaded_file($_FILES['InscricaoMunicipal']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '4';
$sql_InscricaoMunicipal = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_InscricaoMunicipal) or die(mysql_error());
}
if($ComprovanteEndereco != ''){
$uploadfile = $uploaddir . basename($_FILES['ComprovanteEndereco']['name']);
move_uploaded_file($_FILES['ComprovanteEndereco']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '5';
$sql_ComprovanteEndereco = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_ComprovanteEndereco) or die(mysql_error());
}
if($agefip != ''){
$uploadfile = $uploaddir . basename($_FILES['agefip']['name']);
move_uploaded_file($_FILES['agefip']['tmp_name'], $uploadfile);
$nomArquivo = $uploadfile;
$idTipoDocumento = '6';
$sql_agefip = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_agefip) or die(mysql_error());
}
if($rg != ''){
$uploadfile = $uploaddir . basename($_FILES['rg']['name']);
move_uploaded_file($_FILES['rg']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '8';
$sql_rg = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_rg) or die(mysql_error());
}
if($cpf != ''){
$uploadfile = $uploaddir . basename($_FILES['cpf']['name']);
move_uploaded_file($_FILES['cpf']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '9';
$sql_cpf = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_cpf) or die(mysql_error());
}
if($comprovantereisdencia != ''){
$uploadfile = $uploaddir . basename($_FILES['comprovantereisdencia']['name']);
move_uploaded_file($_FILES['comprovantereisdencia']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '10';
$sql_comprovantereisdencia = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_comprovantereisdencia) or die(mysql_error());
}
if($certidaonascimento !=''){
$uploadfile = $uploaddir . basename($_FILES['certidaonascimento']['name']);
move_uploaded_file($_FILES['certidaonascimento']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '11';
$sql_certidaonascimento = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_certidaonascimento) or die(mysql_error());
}
if($certidaocasamento != ''){
$uploadfile = $uploaddir . basename($_FILES['certidaocasamento']['name']);
move_uploaded_file($_FILES['certidaocasamento']['tmp_name'], $uploadfile);
echo $nomArquivo = $uploadfile;
$idTipoDocumento = '12';
$sql_certidaocasamento = 'INSERT INTO documentos (idCliente, idTipoDocumento, nomArquivo) VALUES ('.$idCliente.','.$idTipoDocumento.',"'.$nomArquivo.'")';
mysql_query($sql_certidaocasamento) or die(mysql_error());
}
header('location:lista-propostas.php?docs=1');
}
Here the HTML code:
<form id="form1" name="form1" action="upload-docs.php" method="post" enctype="multipart/form-data">
<input type="hidden" id="idCliente" name="idCliente" value="'.$qt['idCliente'].'">
<h3 class="login-form-text2">Documentos</h3>
<div class="col l3 s12">
Contrato Social
<input type="file" id="ContratoSocial" name="ContratoSocial" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
Cartão CNPJ
<input type="file" id="cnpj" name="cnpj" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
Inscrição Estadual
<input type="file" id="InscricaoEstadual" name="InscricaoEstadual" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
Inscrição Municipal
<input type="file" id="InscricaoMunicipal" name="InscricaoMunicipal" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
</div>
<div class="row">
<div class="col l3 s12">
Comprovante de Endereço
<input type="file" id="ComprovanteEndereco" name="ComprovanteEndereco" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
Cartão AGEFIP
<input type="file" id="agefip" name="agefip" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
R.G.
<input type="file" id="rg" name="rg" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
C.P.F.
<input type="file" id="cpf" name="cpf" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
Comprovante de Residência
<input type="file" id="comprovantereisdencia" name="comprovantereisdencia" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
Certidão de Nascimento
<input type="file" id="certidaonascimento" name="certidaonascimento" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
<div class="col l3 s12">
Certidão de Casamento
<input type="file" id="certidaocasamento" name="certidaocasamento" class="dropify" data-allowed-file-extensions="png jpg jpeg gif bmp pdf" data-show-errors="true" data-max-file-size="5M" data-default-file="">
</div>
</div>
<div class="row">
<div class="input-field col l3 s12">
<input type="date" value="" class="datepicker">
<label class="active" for="dataDigitalizacao">Data de Digitalização</label>
</div>
<div class="input-field col l3 s12">
<input type="date" class="datepicker" disabled value="' . date('d/m/Y') . '">
</ul>
<label class="active" for="dataAlteracao">Data de Alteração</label>
</div>
</div>
<div class="divider"></div>
<br>
<button class="btn waves-effect waves-light" type="submit" name="atualizar" id="atualizar" onClick="javascript:desabilita();">atualizar
<i class="material-icons right">send</i>
</button>
I’ve gone over all the lines and I haven’t figured out the problem yet, how I could fix this?
Example: http://php.net/manual/en/features.file-upload.multiple.php
– novic
Hi Virgilio, I had already seen this page and examples. It seems to me a problem of max_file_uploads, but I don’t know how to fix it. Could I write a php.ini and put it on the server?
– Marcello Patto
I don’t know exactly! but, you showed me no errors and also need to see your html!
– novic
Here’s the html code... it’s long!
– Marcello Patto
max_file_uploads
check on the server which is the maximum you can send, or create a file with the function<?php phpinfo();
and check the size you can send.– novic
I created a php.ini and went up and made a difference. The server reads this file. I will now do the one you suggested to see what happens.
– Marcello Patto
Yes, the server reads php.ini that I put on the server. Time puz 12, time puz 20 and phpinfo(); informed me exactly the changes I made. Must be another problem. Are not going the values $_POST from the 5th query....
– Marcello Patto
It would be simpler then to make a file for each or 12 file identifying each name and code would be simple! i saw a problem that seems multi upload each field that there depending on the case can more mess than help!
– novic