在过去的两天里,我一直在做一个项目,无论我尝试什么,我都会遇到某种错误,或者某些东西不起作用。在这一点上,我被告知我正在调用一个未定义的方法,upload:prepare(),这是真的,因为该类被称为上传,并且语句是 $this->prepare()....等等.
我很沮丧,无论我做什么,我都无法弄清楚这一点。
类.php
<?php
require('config.php');
error_reporting(E_ALL);
/*
* Classes required by the script
*
*/
class database extends PDO
{
public $conURL;
public function __construct($config) {
$conURL = "mysql:host=" . $config['host'] . ";dbname=" . $config['db'];
try {
parent::__construct($conURL, $config['user'], $config['pass']);
} catch (PDOException $e) {
$e->getMessage();
}
}
}
class upload
{
public $_FILES;
public function uploadFile() {
if ($_FILES['file']['size'] >= 2000000) {
echo "File is too large!";
}
elseif (isset($_FILES['file'])) {
$stmt = $this->prepare("INSERT INTO upload (name, type, size, content) VALUES (?, ?, ?, ?)");
$stmt->execute(array($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $_FILES['file']['file']));
}
}
}
配置文件
<?php
$config = array(
'host' => 'localhost', // db host
'user' => 'root', // db user
'pass' => 'mypassword', //db pass
'db' => 'files' // db name
);
上传.php
<?php
error_reporting(E_ALL);
require('config.php');
require('classes.php');
$dbh = new database($config);
$upload = new upload();
$upload->uploadFile();