-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencrypt.php
More file actions
40 lines (36 loc) · 1.16 KB
/
Copy pathencrypt.php
File metadata and controls
40 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$uploadDir = 'uploads/';
$encryptedDir = 'encrypted/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir);
}
if (!is_dir($encryptedDir)) {
mkdir($encryptedDir);
}
$file = $_FILES['file'];
$originalPath = $uploadDir . basename($file['name']);
$encryptedPath = $encryptedDir . basename($file['name']) . '.enc';
// Move uploaded file to the uploads directory
if (move_uploaded_file($file['tmp_name'], $originalPath)) {
// Encrypt the file
$key = 7; // Simple XOR key
$data = file_get_contents($originalPath);
$encryptedData = '';
for ($i = 0; $i < strlen($data); $i++) {
$encryptedData .= chr(ord($data[$i]) ^ $key);
}
file_put_contents($encryptedPath, $encryptedData);
// Return JSON response
echo json_encode([
'success' => true,
'filePath' => $encryptedPath,
'fileName' => basename($encryptedPath),
]);
} else {
echo json_encode(['success' => false]);
}
} else {
echo json_encode(['success' => false]);
}
?>