Download And Encode PDF [PHP]

โจทย์มีอยู่ว่า อ่านค่าใน abc.txt แล้วไปดึงไฟล์ตาม url ที่ระบบไว้ ดึงไฟล์มาจาก clound แล้วนำไฟล์ที่ได้ โหลดมาเก็บที่แคชไฟล์ แล้วนำไฟล์ที่ได้นั้นในแคชไฟล์มาเข้ารหัส และเขียนทับไปในไฟล์แคชเช่นเดิม ...

function downloadAndEncodeFiles

function downloadAndEncodeFiles() {
 // อ่านไฟล์ abc.txt และแปลงข้อมูลเป็น array ของ URLs
 $urls = file('txt/abc.txt', FILE_IGNORE_NEW_LINES);

 // วนลูปตาม URLs
 foreach ($urls as $url) {
  // ดึงชื่อไฟล์จาก URL
  $filename = basename($url);

  // ตั้งชื่อไฟล์ใหม่เพื่อเก็บไว้ในโฟลเดอร์แคช
  $cachedFilename = 'cache/' . $filename;

  // ดาวน์โหลดไฟล์จาก URL และเก็บไว้ในโฟลเดอร์แคช
  file_put_contents($cachedFilename, file_get_contents($url));

  // เข้ารหัสไฟล์ด้วย password "m1n.app"
  $encrypted = openssl_encrypt(
   file_get_contents($cachedFilename),
   'AES-128-CBC',
   'm1n.app',
   OPENSSL_RAW_DATA,
   '0000000000000000'
  );

  // เขียนไฟล์ที่ถูกเข้ารหัสแล้วกลับไปทับไฟล์เดิมในโฟลเดอร์แคช
  file_put_contents($cachedFilename, $encrypted);
 }
}

..

0
208