How can PHP developers ensure data integrity and confidentiality when transferring files between servers using PHP scripts?
To ensure data integrity and confidentiality when transferring files between servers using PHP scripts, developers can use encryption and secure transfer protocols such as HTTPS. By encrypting the data before transmission and ensuring the connection is secure, developers can protect the confidentiality of the information being transferred and prevent unauthorized access or tampering.
// Encrypt the file before transferring
$plaintext = file_get_contents('file_to_transfer.txt');
$encrypted = openssl_encrypt($plaintext, 'AES-256-CBC', 'secret_key', 0, 'iv12345678901234');
// Transfer the encrypted file using a secure protocol like HTTPS
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://destination_server/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => $encrypted));
$response = curl_exec($ch);
curl_close($ch);