-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
44 lines (30 loc) · 793 Bytes
/
upload.php
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
<?php
if (!isset($_FILES["myFile"])) {
die("There is no file to upload!");
}
function fileExtension($s)
{
$n = strrpos($s, ".");
if ($n === false)
return "";
else
return substr($s, $n);
}
$filepath = $_FILES["myFile"]["tmp_name"];
$filesize = filesize($filepath);
// $fileinfo = finfo_open(FILEINFO_MIME_TYPE);
// $filetype = finfo_file($fileinfo, $filepath);
$anotherName = $_FILES["myFile"]["name"];
if ($filesize === 0) {
die("The file is empty");
}
$filename = basename($filepath);
$targetDirectory = __DIR__ . "/uploads";
$newFilePath = $targetDirectory . "/" . $anotherName;
if (!copy($filepath, $newFilePath)) {
die("Cannot move file!");
}
unlink($filepath);
echo "File uploaded successfully!";
header("Refresh:1;URL=index.php");
?>