-4

我不知道代码是否正确,但 MAX FILE SIZE 不起作用

并且不要检查文件是否存在,也许我错误地实现了 isset 或者代码中有什么东西。

ps给我这个错误:

注意:未定义变量:ecc../ecc 中的内容。在第 23 行

注意:未定义变量:ecc../ecc 中的 fp。在第 24 行

这是代码:

<?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 &nbsp";

                    }else{

                         echo "Errore &nbsp" . $this->mysqli->error; 

                        }   
                }
            }           
    }

$form = new Check();
$form->checkImage();    

?>
4

2 回答 2

0

您在哪里定义要传递给 ACheckImage 类中的 __construct() 的 $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');
       }

     }

}
?>
于 2013-02-06T17:14:36.713 回答
0

您的问题之一是:

         public $conent;

您将它(在第 23 行)称为$this->content,然后将其设置为等于未定义的局部变量$content

相同的问题$this->fp。那时在您的构造函数中,您还没有定义局部变量$fp是什么,那么 PHP 应该如何知道呢?也许您应该将它传递给构造函数?

另外,如果我没记错的话,如果MAX_FILE_SIZE违反了,那么服务器上将不存在该文件,并且$_FILES不会填充该数组。

于 2013-02-06T17:13:07.920 回答