I have a code on my page that uploads files.
These files that are sent, have specific fields filled in (Ex: name, phone, email) and you can not change this type of document. If the person leaves a field blank, they will be left blank. However I need this information.
The upload is sent by jQuery to another PHP page where the whole process of reading this document is saved and saved in the database and returns a message (sucess / error).
My question is, is there any way to, when I notice the blank field in the document returning the message, open a popup, and the person filling an input, and resume the AJAX where did you stop with the new information?
Thanks, I use the following code to display HTML:
<form id="upload" method="post" action="upload.php" enctype="multipart/form-data">
<div id="drop">
Arraste os arquivos ZIP aqui
<br/>
<a>Pesquisar...</a>
<input type="file" name="upl" multiple />
</div>
<ul>
<!-- The file uploads will be shown here -->
</ul>
</form>
<!-- JavaScript Includes -->
<script src="assets/js/jquery.knob.js"></script>
<!-- jQuery File Upload Dependencies -->
<script src="assets/js/jquery.ui.widget.js"></script>
<script src="assets/js/jquery.iframe-transport.js"></script>
<script src="assets/js/jquery.fileupload.js"></script>
<!-- Our main JS file -->
<script src="assets/js/script.js"></script>
Along with the library of jQuery File Upload
'upload.php' where FORM is sent without page reload:
$allowed = array('zip');
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$filename = $_FILES['upl']['name'];
$source = $_FILES['upl']['tmp_name'];
$type = $_FILES['upl']['type'];
$name = explode('.', $filename);
$target = 'uploads/extracted/' . $name[0] . '-' . time() . '/';
$target2 = 'uploads/extracted/' . $name[0] . '-' . time();
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error"}';
exit;
}
if(move_uploaded_file($source, 'uploads/'.$filename)){
// INICIA CÓDIGO PARA SALVAR INFO NO DB
// Solicita NANODicom
require 'nanodicom/nanodicom.php';
// Cria pasta caso não exista
if(!is_dir($target)){
mkdir($target, 0744);
}
$zip = new ZipArchive();
$x = $zip->open('uploads/'.$filename);
// Extrai arquivos
if($x === true) {
$zip->extractTo($target);
$zip->close();
} else {
echo '{"status":"error"}';
exit;
}
// Procura por arquivos DCM nas pastas
$ar = array();
$studyID = array();
$files = findDcm($target2);
// INICIO da leitura dos DCM com NANODicom
if($files === true){
foreach ($ar as $file){
try{
// 2) Load only given tags. It will stop once all given tags are found. Fastest!
$dicom = Nanodicom::factory($file, 'simple');
// Only a small subset of the dictionary entries were loaded
$dicom->parse()->profiler_diff('parse')."<br/>";
// Verifica se existe exames diferentes
if(!in_array($dicom->value(0x0020, 0x0010), $studyID) || !count($studyID)){
$studyID[] = $dicom->value(0x0020, 0x0010);
$exame = saveStudy($dicom, "uploads/$filename");
if(!$exame){
echo '{"status":"error"}';
exit;
}
}
unset($dicom);
} catch (Nanodicom_Exception $e){
echo '{"status":"error"}';
exit;
}
}
} else{
echo '{"status":"error"}';
exit;
}
// FIM da leitura dos DCM
// Exclui pasta para ganhar espaço
$result = delTree($target2);
// FIM CÓDIGO PARA SALVAR INFO NO DB
echo '{"status":"success"}';
exit;
} else{
echo 'erro ao gravar arquivo.';
echo '{"status":"error"}';
exit;
}
}
//echo 'erro arquivo: '.$_FILES['upl']['error'];
echo '{"status":"error"}';
exit;
The findDcm () function searches folder by folder for files with .dcm which is the file type that is sent.
The saveStudy () function saves the variables in the database.
Checking whether the value inside the file exists can be done both here and saveStudy (), but as soon as you verify that a value is blank you need to return some message with an input field for the user to fill in the missing value .