-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuploader.php
More file actions
29 lines (26 loc) · 763 Bytes
/
uploader.php
File metadata and controls
29 lines (26 loc) · 763 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
27
28
29
<?php
//code gotten from course wiki to upload file
session_start();
// Get the filename and make sure it is valid
$filename = basename($_FILES['uploadedfile']['name']);
if(!preg_match('/^[\w_\.\-]+$/', $filename) ){
echo "Invalid filename<br>";
echo $_FILES['uploadedfile']['tmp_name'];
exit;
}
// Get the username and make sure it is valid
$username = $_SESSION['username'];
if( !preg_match('/^[\w_\-]+$/', $username) ){
echo "Invalid username";
exit;
}
$full_path = sprintf("/home/ryan38538/%s/%s", $username, $filename);
$f="/home/ryan38538/public_html";
if( move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $full_path) ){
header("Location: dashboard.php");//redirect back to dashboard after upload
exit;
}else{
echo $full_path;
exit;
}
?>