uploading image to user_content dir
This commit is contained in:
parent
fd462ce88d
commit
a139e6ca48
@ -30,7 +30,9 @@ if (!isset($_POST["name"]))
|
|||||||
goto send;
|
goto send;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array(strtolower(pathinfo($_FILES["file_upload"]["name"], PATHINFO_EXTENSION)), $supported_formats))
|
$file_format = strtolower(pathinfo($_FILES["file_upload"]["name"], PATHINFO_EXTENSION));
|
||||||
|
|
||||||
|
if (!in_array($file_format, $supported_formats))
|
||||||
{
|
{
|
||||||
$status = 3;
|
$status = 3;
|
||||||
goto send;
|
goto send;
|
||||||
@ -47,6 +49,23 @@ if (!$res["admin"])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$user_id = $res["id"];
|
||||||
|
$dir = "../../../user_content/" . $user_id;
|
||||||
|
|
||||||
|
if (!(file_exists($dir) && is_dir($dir)))
|
||||||
|
{
|
||||||
|
mkdir($dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
$safe_name = mysqli_real_escape_string($database, $_POST["name"]);
|
||||||
|
$safe_desc = isset($_POST["desc"]) ? mysqli_real_escape_string($database, $_POST["desc"]) : null;
|
||||||
|
|
||||||
|
$photo_id = count(glob($dir . "/*"));
|
||||||
|
|
||||||
|
$database -> query("INSERT INTO post (title, description, author, photo_id) VALUES (\"" . $safe_name . "\", " . ($safe_desc == null ? "NULL" : "\"" . $safe_desc . "\"") . ", " . $user_id . ", " . $photo_id . ")");
|
||||||
|
|
||||||
|
move_uploaded_file($_FILES["file_upload"]["tmp_name"], $dir . "/" . $photo_id . "." . $file_format);
|
||||||
|
|
||||||
send:
|
send:
|
||||||
header('Content-type: application/json');
|
header('Content-type: application/json');
|
||||||
echo json_encode(["status" => $status]);
|
echo json_encode(["status" => $status]);
|
Loading…
x
Reference in New Issue
Block a user