1
제목에서 언급 한 오류가 33 행에 (분명히) 발생하고 있습니다.이 문제를 최적화 할 수있는 방법이나 일반적인 제안이 있다면 부수적으로, 나는 모든 귀이다. 감사!PDO 클래스의 객체를 문자열로 변환 할 수 없습니다
<?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);
첫 번째 제안, 행 33은 – Ibu
'global'입니까? 왜 변수를 세계화?! –
왜 글로벌 $ dbcon을 사용하고 있습니까? – Panagiotis