我已經創建了這個PHP代碼上傳文件到我的數據庫(phpMyAdmin),但我不知道如何使它在WordPress上工作。上傳文件到數據庫PHP/WordPress
$con = mysqli_connect("localhost","root","","mydb");
if (mysqli_connect_errno()) {
echo "Unable to connect to MySQL! ". mysqli_connect_error();
}
if (isset($_POST['submit'])) {
$target_dir = get_template_directory_uri() .'/Uploaded_Files';
$target_file = $target_dir . date("dmYhis") . basename($_FILES["file"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if($imageFileType != "jpg" || $imageFileType != "png" || $imageFileType != "jpeg" || $imageFileType != "gif") {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
$files = date("dmYhis") . basename($_FILES["file"]["name"]);
} else {
echo "Error Uploading File";
exit;
}
} else {
echo "File Not Supported";
exit;
}
$filename = $_POST['filename'];
$location = get_template_directory_uri() .'/Uploaded_Files . $files';
$getuser = $_SESSION['id'];
$settime = date("Y-m-d H:i:s");
$setmsg = $con->real_escape_string($_POST['msg']);
// Database Query goes here.
}
_注意:_ phpMyAdmin是不是一個數據庫,它是一個基於Web的管理MySQL數據庫的工具。 –
https://codex.wordpress.org/Uploading_Files – jdv
哦!我不是指PHPmyadmin作爲數據庫。無論如何。 – devsam247