标题中引用的错误(显然)发生在第 33 行。作为旁注,如果您对我可以优化它的方法有任何建议,或者只是一般性建议,我会全力以赴。谢谢!
这是代码:
<?php
error_reporting(E_ALL);
require('config.php');
$filename = htmlentities($_FILES['file']['name']);
$tmpname = $_FILES['file']['tmp_name'];
$filesize = $_FILES['file']['size'];
$filetype = $_FILES['file']['type'];
$file = $_FILES['file'];
class connect {
public function dbConnect($host, $user, $pass, $dbname) {
try {
global $dbcon;
$dbcon = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
}
catch (PDOException $e) {
print $e->getMessage();
}
}
}
class upload Extends connect {
public function uploadFile($dbcon, $filename, $filesize, $filetype, $file) {
if ($filesize > 2000000) {
echo "File too large!";
}
elseif ($filesize <= 2000000) {
$stmt = $dbcon->prepare("INSERT INTO upload (name, type, size, content) VALUES (?, ?, ?, ?)");
$stmt->$dbcon->bindParam(1, $filename);
$stmt->$dbcon->bindParam(2, $filetype);
$stmt->$dbcon->bindParam(3, $filesize);
$stmt->$dbcon->bindParam(4, $file);
$stmt->$dbcon->execute();
$stmt->$dbcon->close();
echo "File uploaded!";
}
else {
echo "Unexpected error! Please try again!";
}
}
}
$con = new connect;
$con->dbConnect($host, $user, $pass, $dbname);
$exec = new upload;
$exec->uploadFile($dbcon, $filename, $filesize, $filetype, $file);