我在使用这个脚本时遇到了问题。这是一个图像上传脚本,我收到了两个相同的错误:
警告:DoUpload::doUpload() 缺少参数 1,在第 8 行的 /var/www/vhosts/mysite.net/httpdocs/mp/upload.php 中调用并在 /var/www/vhosts/mysite.net/ 中定义第 26 行的 httpdocs/mp/includes/classes.php 文件已上传!警告:DoUpload::doUpload() 缺少参数 1,在第 10 行的 /var/www/vhosts/mysite.net/httpdocs/mp/upload.php 中调用并在 /var/www/vhosts/mysite.net/ 中定义第 26 行 httpdocs/mp/includes/classes.php 上传文件时出错!
但正如您在upload.php 中看到的,我传递了一个参数:$_FILES 数组。
我该怎么办?(不寻找任何人来重写任何东西,我只需要一些关于我做错了什么的指导。:))
类.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 'on');
require('config.php');
// Connect to database
// Does not handle anything else
class DatabaseCon {
public $dbh;
// Method to connect to database
function dbConnect($config) {
try {
$this->dbh = new PDO("mysql:host=" . $config['host'] . ";dbname=" . $config['dbname'], $config['dbuser'], $config['dbpass']);
$this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
}
class DoUpload {
private $target_path = 'i/';
public $_FILES;
public function doUpload($_FILES) {
$this->target_path .= basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $this->target_path)) {
echo "The file has been uploaded!";
}
else {
echo "An error occurred when uploading the file!";
}
}
}
上传.php
<?php
ini_set('display_errors', 1);
require_once('includes/config.php');
require_once('includes/classes.php');
$db = new DatabaseCon();
$db->dbConnect($config);
$upload = new DoUpload();
$upload->doUpload($_FILES);
$sth = $db->prepare("INSERT INTO images (filename) VALUES (?)");
$sth->bindParam(1, $_FILES['file']['tmp_name']);
$sth->execute();