-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlecNote_upload.php
More file actions
45 lines (36 loc) · 1.28 KB
/
lecNote_upload.php
File metadata and controls
45 lines (36 loc) · 1.28 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
41
42
43
44
45
<?php
//to insert a log into database
include_once(dirname(__FILE__).'/dbOperations/db_lectureNote_log.php');
//upload a lecture note (maximum 10MB)
$mod_name = $_POST['mod_name'];
$target_dir = "File Upload/Lecture Notes/" . trim($mod_name);
//create a folder for module if not exists
if( !file_exists($target_dir) ){
mkdir( "{$target_dir}" );
}
$target_dir .= "/";
$target_file = $target_dir . basename( $_FILES["fileToUpload"]["name"] );
basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
// Check if file already exists
if ( file_exists($target_file) ) {
echo "Sorry, the selected file already exists!";
$uploadOk = 0;
return;
}
// Check file size
if ( $_FILES["fileToUpload"]["size"] > 10000000 ) {
echo "Sorry, your file is larger than 10MB!";
$uploadOk = 0;
return;
}
// try to upload the file
if ($uploadOk == 1) {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
addLog( $_FILES["fileToUpload"]["name"], $mod_name, $target_dir.basename( $_FILES["fileToUpload"]["name"]) );
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>