38 lines
1.1 KiB
PHP
38 lines
1.1 KiB
PHP
<?php
|
|
|
|
require("../../inc/connect.php");
|
|
$relative_dir = "../../";
|
|
|
|
$name = $_POST['name'];
|
|
$project = $_POST['project'];
|
|
$uid = $_POST['uid'];
|
|
$filename = basename($_FILES["file"]["name"]);
|
|
|
|
//Get the directory name
|
|
$query = "SELECT `uid` FROM project WHERE `id`=$project";
|
|
$temp = ExecQuery($query);
|
|
$result = $temp->fetch_assoc();
|
|
$dir = $relative_dir . "download/" . $result['uid'];
|
|
$target_file = $dir . "/" . $filename;
|
|
|
|
//Create the directory
|
|
if (! file_exists($dir)) {
|
|
mkdir($dir, 0755, true);
|
|
}
|
|
|
|
$extension = pathinfo($target_file,PATHINFO_EXTENSION);
|
|
|
|
//Try to move the file
|
|
if (! move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
|
|
header("Location: /ptf-admin/add?success=false");
|
|
exit;
|
|
}
|
|
|
|
//Update the database
|
|
$stmt = $mysqli->prepare("INSERT INTO file (`name`, `uid`, `file`, `project-id`) VALUES (?,?,?,?)");
|
|
$stmt->bind_param("sssi", $name, $uid, $filename, $project);
|
|
$stmt->execute();
|
|
$stmt->close();
|
|
|
|
header("Location: /ptf-admin/add?success=true");
|
|
?>
|