0
I have a code on my page that uploads files.
These files that are sent, have specific fields filled (Ex: name, phone, email) and it is not possible to change this type of document. If one leaves a field blank, it will be blank. However I need this information.
The upload is sent by jQuery to another PHP page where the whole process of reading this document and saving in the database is done and returns a message (sucess/ error).
My question is, is there any way to, upon noticing the blank field in the document return the message, open a popup, and fill in an input, and resume AJAX from where it left off with the new information?
Thank you, I use the following code for HTML view:
<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>
Together with the library of jQuery File Upload
'upload.php' to where the 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 function findDcm() searches folder by folder by files with . dcm which is the file type that is sent.
The saveStudy() function saves variables in the database.
Checking whether the value exists inside the file can be done both here and in saveStudy(), but once you check that a value is empty you need to return some message with an input field for the user to fill in the missing value.
Yes, it’s called input validation. You can enter the form code you have?
– Sergio
I edited the post to fit the code, however I don’t think you understand. The library to read the document that is sent is in PHP, so I need to send AJAX to know which fields are missing. And save in the database. I don’t have the information before sending it
– Felipe Bueno
Okay, so you want PHP to send the request to the client side and "wait for the answer" to continue? but how is this data sent? Isn’t it on the client side? You have access to that code?
– Sergio
This is the whole code. The data is sent without reloading the page, the entire upload is done by the File Upload library, it sends the form to upload.php without reloading the page to the user. and returns a success or error message.
– Felipe Bueno