How to get status of binary data transferred though php fwrite function using ajax - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Tuesday, May 2, 2023

How to get status of binary data transferred though php fwrite function using ajax

Hello everyone I am writing an application in which we are saving pdf data as binary data using ajax and php fwrite function my files are as follows:

**index.html**

$.ajax({
            url: './ajax_create_pdf.php',
            type: 'POST',
            dataType: 'JSON',
            data: {'base64data':data,
                   'original_file_url':inputFilePath,
            },
            
            
            success: function(response){
                
               
            
            }
            
            
        });//end of ajax function

**ajax_create_pdf.php**

<?php

$pdfData = $_POST['base64data'];

$original_file_url= $_POST['original_file_url'];

$docs_group_name="QR_DOCS";

// Decode the base64-encoded PDF data
$pdfBinaryData = base64_decode($pdfData);

// Define the path and filename for the PDF file

$pdfFilename = $original_file_url;

$pdfFilename2=str_replace(".pdf","_qr.pdf",$pdfFilename);

$pdfFilePath =  $pdfFilename2;

// Save the PDF file
$file = fopen($pdfFilePath, 'wb');
fwrite($file, $pdfBinaryData);
fclose($file);

//echo 'PDF file saved successfully.'


?>

Requirement is to notify the user which is at **index.html** file with the progress of data transferred at every 5 seconds time interval. So that user can be assured that their data fully transferred to the server.

plz help ...



source https://stackoverflow.com/questions/76148928/how-to-get-status-of-binary-data-transferred-though-php-fwrite-function-using-aj

No comments:

Post a Comment