PHP回调包含


PHP callback contains

我已经在PHP中创建了一个类:

<?php
class _new_model extends model {
/**
 * NEW contruct
 */
public function __construct() {
    parent::__construct();
}
function newuser(){
    $password = trim($_POST['psw']);
    $password2= trim($_POST['psw1']);
    if($password === $password2){
        $hashpsw = hash('sha512', $password);
        $salt = $this->createSalt();
        $psw = hash('sha512', $salt . $hashpsw);
        $query = $this->db->prepare('INSERT INTO users (username, password, salt) VALUES (?,?,?)');
        $query->bindValue(1, $_POST['user'], PDO::PARAM_STR);
        $query->bindValue(2, $psw, PDO::PARAM_STR);
        $query->bindValue(3, $salt, PDO::PARAM_STR);
        try{
            if($query->execute()){
                echo 'ჩაიწერა!';
            }else{
                echo 'მოხდა შეცდომა!';
            }
        }catch(PDOException $e){
            die($e->getMessage());
        }
    }else{
        echo 'პაროლები ერთმანეთს არ ემთხვევა!';
    }
}
/**
 * @return string
 */
function createSalt(){
    $text = md5(uniqid(rand(), TRUE));
    $salt = substr($text, 0, 32);
    return $salt;
}
function newlanguage(){
    $lang = trim($_POST('language'));
    $checklang = $this->checklang($lang);
    if($checklang == true){
        echo 'ეს ენა უკვე არსებობს';
    }else{
        if(is_uploaded_file($_FILES['flag']['tmp_name'])){
            $maxsize=100000;
            $size=$_FILES['flag']['size'];
            $imgdetails = getimagesize($_FILES['flag']['tmp_name']);
            $mime_type = $imgdetails['mime'];
            // checking for valid image type
            if(($mime_type=='image/jpeg')||($mime_type=='image/gif')||($mime_type=='image/bmp')||($mime_type=='image/png')){
                // checking for size again
                if($size<$maxsize){
                    $filename=$_FILES['flag']['name'];
                    $imgData =addslashes (file_get_contents($_FILES['flag']['tmp_name']));
                    $query = $this->db->prepare('INSERT INTO lang (name,mokled,flag,flagname,flagtype,flagsize) VALUES (?,?,?,?,?,?)');
                    $query->bindValue(1, $lang, PDO::PARAM_STR);
                    $query->bindValue(2, trim($_POST('shortlang')), PDO::PARAM_STR);
                    $query->bindValue(3, $imgData, PDO::PARAM_LOB);
                    $query->bindValue(4, $filename, PDO::PARAM_STR);
                    $query->bindValue(5, $mime_type, PDO::PARAM_STR);
                    $query->bindValue(6, addslashes($imgdetails[3]), PDO::PARAM_STR);
                    try{
                        if($query->execute()){
                            echo 'yes';
                        }else{
                            echo 'no query-ის გაშვებისას';
                        }
                    }catch (PDOException $e){
                        die($e->getMessage());
                    }
                }else{
                    echo "<span class='error'>Image to be uploaded is too large..Error uploading the image!!</span>";
                }
            }else{
                echo "<span class='error'>Not a valid image file! Please upload jpeg or gif image.</span>";
            }
        }else{
            switch($_FILES['flag']['error']){
                case 0: //no error; possible file attack!
                    echo "<span class='error'>There was a problem with your upload.</span>";
                    break;
                case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
                    echo "<span class='error'>The file you are trying to upload is too big.</span>";
                    break;
                case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
                    echo "<span class='error'>The file you are trying to upload is too big.</span>";
                    break;
                case 3: //uploaded file was only partially uploaded
                    echo "<span class='error'>The file you are trying upload was only partially uploaded.</span>";
                    break;
                case 4: //no file was uploaded
                    echo "<span class='error'>You must select an image for upload.</span>";
                    break;
                default: //a default error, just in case!
                    echo "<span class='error'>There was a problem with your upload.</span>";
                    break;
            }
        }
    }
}
/**
 * @param $name
 * @return bool
 */
function checklang($name){
    $query = $this->db->prepare('SELECT id FROM lang WHERE name = ?');
    $query->bindValue(1, $name, PDO::PARAM_STR);
    try{
        $query->execute();
        if($query->rowCount() > 0){
            return true;
        }else{
            return false;
        }
    }catch (PDOException $e){
        die($e->getMessage());
    }
}}
还有这个HTML表单:
<form enctype="multipart/form-data" action="<?php echo Domain; ?>_new/newlanguage/" name="newlanguage" method="post" id="newlanguage" >
<input type="text" name="language" id="language" placeholder="New Language">
<input type="text" name="shortlang" id="shortlang" placeholder="short name"><br>
<input type="file" name="flag" id="flag" placeholder="Flag"><br>
<input type="submit" name="submit" value="submit"></form>

当提交表单时,我得到这个错误:

数组回调必须包含第49行_new_model.php中的索引0和1这条线上写着返回$盐;

这个函数的名称是create salt。我不明白当我调用newlanguage函数时,为什么它会扫描另一个函数?

请帮

$_POST('language')应为$_POST['language']