Necesito obtener una matriz de $datos desde el backend hasta el frontend para organizarlo para su visualización. Solo puedo encontrar ejemplos usando jQuery Ajax.
<!DOCTYPE html> <html> <style> .table_class{ display:none; } </style> <script> async function uploadFile() { let formData = new FormData(); formData.append("file", fileupload.files[0]); console.log(formData); await fetch('file_ingest.php', { method: "POST", body: formData, }); var test = document.getElementById("test"); test.innerText = ('The file has been uploaded successfully.'); //var returned_vals = JSON.parse(formData.responseText); //console.log(returned_vals); } </script> <body> <input id="fileupload" type="file" name="fileupload" /> <button id="upload-button" onclick="uploadFile()"> Upload </button> <p id = "test"></p> </body> </html>Necesito obtener una matriz de $datos desde el backend hasta el frontend para organizarlo para su visualización. Solo puedo encontrar ejemplos usando jQuery Ajax.
<?php set_time_limit(120); /* Get the name of the uploaded file */ $filename = $_FILES['file']['name']; /* Choose where to save the uploaded file */ $location = "uploads/".$filename; if ( move_uploaded_file($_FILES['file']['tmp_name'], $location) ) { echo 'Success'; } else { echo 'Failure'; $CSVfp = fopen("uploads/${filename}", "r"); if($CSVfp !== FALSE) { while(! feoF($CSVfp)) { $data = fgetcsv ($CSVfp, 1000, ","); print json_encode($data); //echo $data; } } fclose($CSVfp);<?php set_time_limit(120); // if you need this you may have other problems /* Get the name of the uploaded file */ $filename = $_FILES['file']['name']; /* Choose where to save the uploaded file */ $location = "uploads/".$filename; $response = []; /* Save the uploaded file to the local filesystem */ if ( move_uploaded_file($_FILES['file']['tmp_name'], $location) ) { $response['status'] = 'Files Save Success'; // read the file here, if it failed the upload and move // there is no point trying to read it if (($fp = fopen($location, "r")) !== FALSE) { while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) { $response['data'][] = $data } fclose($fp); } } else { $response['status'] = 'File Save Failure'; } // now you can return either an error or a success and data echo json_encode($response);Ahora debe verificar el javascript para buscar el estado en el lugar correcto y descargar los datos de la fila del lugar correcto