PHP OOP-上传表单后设置和文件大小不起作用
我不知道代码是否正确,但最大文件大小不起作用 不要检查文件是否存在,也许我实现错了 设置或代码中有某些内容 p、 请告诉我这个错误: 注意:未定义变量:ecc中的内容../ecc。第23行 注意:未定义变量:ecc../ecc中的fp。在线24 代码如下:PHP OOP-上传表单后设置和文件大小不起作用,php,isset,Php,Isset,我不知道代码是否正确,但最大文件大小不起作用 不要检查文件是否存在,也许我实现错了 设置或代码中有某些内容 p、 请告诉我这个错误: 注意:未定义变量:ecc中的内容../ecc。第23行 注意:未定义变量:ecc../ecc中的fp。在线24 代码如下: <?php interface ICheckImage { public function checkImage(); } abstract class ACheckImage impleme
<?php
interface ICheckImage {
public function checkImage();
}
abstract class ACheckImage implements ICheckImage {
public $fileName;
public $tmpName;
public $filesSize;
public $fileType;
public $fp;
public $conent;
protected $mysqli;
public function __construct(){
$this->fileName = $_FILES['userfile']['name'];
$this->tmpName = $_FILES['userfile']['tmp_name'];
$this->filesSize = $_FILES['userfile']['size'];
$this->fileType = $_FILES['userfile']['type'];
$this->content = $content;
$this->fp = $fp;
$this->mysqli = new mysqli('localhost','root','root','test');
}
}
class Check extends ACheckImage {
public function checkImage(){
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0){
$this->fileName = $_FILES['userfile']['name'];
$this->tmpName = $_FILES['userfile']['tmp_name'];
$this->filesSize = $_FILES['userfile']['size'];
$this->fileType = $_FILES['userfile']['type'];
$this->fp = fopen($this->tmpName, 'r');
$this->content = fread($this->fp, filesize($this->tmpName));
$this->content = addslashes($this->content);
fclose($this->fp);
if(!get_magic_quotes_gpc()){
$this->fileName = addslashes($this->fileName);
}
if ($this->mysqli->query("INSERT INTO upload_images (name, size, type, content ) ".
"VALUES ('$this->fileName', '$this->filesSize', '$this->fileType', '$this->content')")){
echo "Upload avvenuto  ";
}else{
echo "Errore  " . $this->mysqli->error;
}
}
}
}
$form = new Check();
$form->checkImage();
?>
你的问题之一是:
public $conent;
您在第23行将其引用为$this->content,然后将其设置为未定义的局部变量$content
$this->fp也有同样的问题。在构造函数中,您还没有定义局部变量$fp是什么,那么PHP应该如何知道呢?也许你应该把它传给构造器
另外,如果我没记错的话,如果违反了MAX_FILE_大小,那么该文件将不存在于服务器上,$_FILES数组将不会被填充。在哪里定义要传递给ACheckImage类中的u构造的$content和$fp变量 如果确实要为变量设置空值,请尝试更改:
<?php
abstract class ACheckImage implements ICheckImage {
public $fileName;
public $tmpName;
public $filesSize;
public $fileType;
public $fp;
public $conent;
protected $mysqli;
public function __construct(){
if (count($_FILES)>0) {
$this->fileName = $_FILES['userfile']['name'];
$this->tmpName = $_FILES['userfile']['tmp_name'];
$this->filesSize = $_FILES['userfile']['size'];
$this->fileType = $_FILES['userfile']['type'];
$this->content = '';
$this->fp = '';
$this->mysqli = new mysqli('localhost','root','root','test');
}
}
}
?>
$this->content=$content//$内容未定义局部变量$this->fp=$fp//$内容未定义局部变量我没有得到任何东西。错误消息是非常不言自明的。给出了偶数行号。为什么调试自己的代码如此困难?是的,但这不是问题吗..谢谢可能是重复的谢谢,但还有一个问题。。如果我在表单中单击upload,并且没有选择任何文件,结果是一个没有错误的空白页。为什么?你在PHP中打开了错误报告吗?通常,我会验证数组是否有值。如果没有,它将继续在代码上运行。尝试使用if count$\u FILES>0这样的if语句。编辑了我的代码。