2017-10-10 150 views
1

我已經創建了這個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. 
} 
+0

_注意:_ phpMyAdmin是不是一個數據庫,它是一個基於Web的管理MySQL數據庫的工具。 –

+0

https://codex.wordpress.org/Uploading_Files – jdv

+0

哦!我不是指PHPmyadmin作爲數據庫。無論如何。 – devsam247

回答

0

通常當我們導出數據庫從在WordPress站點它顯示了這樣的代碼,它提供了有關WordPress插件頁面等等等等表的信息

-- Table structure for table `wp_commentmeta` 
-- 

CREATE TABLE IF NOT EXISTS `wp_commentmeta` (
    `meta_id` bigint(20) unsigned NOT NULL, 
    `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0', 
    `meta_key` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, 
    `meta_value` longtext COLLATE utf8mb4_unicode_ci 
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 


AT the head of exported sql sheet it shows... 

-- phpMyAdmin SQL Dump 
-- version 4.3.8 
-- http://www.phpmyadmin.net 
-- 
-- Host: localhost 
-- Generation Time: Oct 10, 2017 at 11:57 AM 
-- Server version: 5.5.51-38.2 
-- PHP Version: 5.6.20 

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; 
SET time_zone = "+00:00"; 


/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */; 
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */; 
/*!40101 SET @[email protected]@COLLATION_CONNECTION */; 
/*!40101 SET NAMES utf8 */; 

-- 
-- Database: database name