forked from Voorivex/voorivex-weblog-owasp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
26 lines (23 loc) · 849 Bytes
/
Copy pathupload.php
File metadata and controls
26 lines (23 loc) · 849 Bytes
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
<?php
session_start();
$uploadDirectory = "./statics/images/"; // Directory to store uploaded images
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_FILES["image"])) {
$file = $_FILES["image"];
// Check for errors during upload
if ($file["error"] === UPLOAD_ERR_OK) {
// Generate a unique filename to prevent overwriting
$filename = md5($_SESSION['user_id']) . ".png";
$destination = $uploadDirectory . $filename;
// Move the uploaded file to the specified directory
if (move_uploaded_file($file["tmp_name"], $destination)) {
echo "Image uploaded successfully. File name: " . $filename;
} else {
echo "Error: Failed to move the uploaded file.";
}
} else {
echo "Error: " . $file["error"];
}
} else {
echo "Invalid request.";
}
?>