Simple upload filter script for Article 13 of EU copyright reform
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.7 KiB

  1. <?php
  2. require_once('db.php');
  3. foreach($_FILES as $file){
  4. $fileHash = hash_file ('sha512' , $file['tmp_name']);
  5. // TODO: file hash lookup for duplicate uploads
  6. $filePath = $CONFIG['fileDir'] . basename($file['name']);
  7. // TODO: duplicate file name check
  8. move_uploaded_file($file['tmp_name'], $filePath);
  9. $query = $db->prepare("INSERT INTO files (filePath,fileHash) VALUES (:filePath,:fileHash);");
  10. $query->execute(array(':filePath' => $filePath, ':fileHash' => $fileHash));
  11. $fileId = $db->lastInsertId();
  12. $query = $db->prepare("SELECT * FROM emails WHERE id IN (SELECT id FROM emails ORDER BY RANDOM() LIMIT :limit);");
  13. $query->execute(array(':limit' => $CONFIG['validationCount']));
  14. $emails = $query->fetchAll(PDO::FETCH_ASSOC);
  15. for($i = 0; $i < $CONFIG['validationCount']; $i++) {
  16. $token = bin2hex(openssl_random_pseudo_bytes(32));
  17. // TODO: duplicate token check
  18. $email = $emails[$i]['email'];
  19. $firstName = $emails[$i]['firstName'];
  20. $lastName = $emails[$i]['lastName'];
  21. $query = $db->prepare("INSERT INTO validations (fileId,email,token) VALUES (:fileId,:email,:token);");
  22. $query->execute(array(':fileId' => $fileId, ':email' => $email, ':token' => $token));
  23. $subject = 'Please validate file to satisfy copyright';
  24. $template = file_get_contents($CONFIG['emailTemplate'], FILE_USE_INCLUDE_PATH);
  25. $message = strtr($template, array('$firstName' => $firstName, '$lastName' => $lastName, '$token' => $token));
  26. $headers = 'From: webmaster@example.com' . "\r\n" .
  27. 'Reply-To: webmaster@example.com' . "\r\n" .
  28. 'X-Mailer: PHP/' . phpversion();
  29. mail($email, $subject, $message, $headers);
  30. }
  31. }