search
HomeBackend DevelopmentPHP Tutorial使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

 $uploadImg= new FileUpload;
                  if($uploadImg ->upload("head")){
                    echo '<pre class="brush:php;toolbar:false">';
                    var_dump($uploadImg ->getFileName());
                    echo '
'; }else{ echo '
';
                    var_dump($uploadImg ->getErrorMsg());
                    echo '
'; }
<code>                  <?php class FileUpload {    
        private $path = "./uploads";                          //上传文件保存的路径
        private $allowtype = array('jpg','jpeg','gif','png');     //设置限制上传文件的类型
        private $maxsize = 1000000;                      //限制文件上传大小(字节)
        private $israndname = true;                       //设置是否随机重命名文件, false不随机
        
        private $originName;                                //源文件名
        private $tmpFileName;                            //临时文件名
        private $fileType;                                  //文件类型(文件后缀)
        private $fileSize;                               //文件大小
        private $newFileName;                               //新文件名
        private $errorNum = 0;                            //错误号
        private $errorMess="";                           //错误报告消息
        
        /**
         * 用于设置成员属性($path, $allowtype,$maxsize, $israndname)
         * 可以通过连贯操作一次设置多个属性值
         *@param    string    $key    成员属性名(不区分大小写)
         *@param    mixed    $val    为成员属性设置的值
         *@return    object            返回自己对象$this,可以用于连贯操作
         */
        function set($key, $val){
            $key = strtolower($key); 
            if( array_key_exists( $key, get_class_vars(get_class($this) ) ) ){
                $this->setOption($key, $val);
            }
            return $this;
        }

        /**
         * 调用该方法上传文件
         * @param    string    $fileFile    上传文件的表单名称 
         * @return    bool                 如果上传成功返回数true 
         */
        
        function upload($fileField) {
            $return = true;
            /* 检查文件路径是滞合法 */
            if( !$this->checkFilePath() ) {                
                $this->errorMess = $this->getError();
                return false;
            }
            /* 将文件上传的信息取出赋给变量 */
            $name = $_FILES[$fileField]['name'];
            $tmp_name = $_FILES[$fileField]['tmp_name'];
            $size = $_FILES[$fileField]['size'];
            $error = $_FILES[$fileField]['error'];

            /* 如果是多个文件上传则$file["name"]会是一个数组 */
            if(is_Array($name)){          
                $errors=array();
                /*多个文件上传则循环处理 , 这个循环只有检查上传文件的作用,并没有真正上传 */
                for($i = 0; $i setFiles($name[$i],$tmp_name[$i],$size[$i],$error[$i] )) {
                        if(!$this->checkFileSize() || !$this->checkFileType()){
                            $errors[] = $this->getError();
                            $return=false;    
                        }
                    }else{
                        $errors[] = $this->getError();
                        $return=false;
                    }
                    /* 如果有问题,则重新初使化属性 */
                    if(!$return)                      
                        $this->setFiles();
                }
            
                if($return){
                    /* 存放所有上传后文件名的变量数组 */
                    $fileNames = array();               
                    /* 如果上传的多个文件都是合法的,则通过销魂循环向服务器上传文件 */
                    for($i = 0; $i setFiles($name[$i], $tmp_name[$i], $size[$i], $error[$i] )) {
                            $this->setNewFileName(); 
                            if(!$this->copyFile()){
                                $errors[] = $this->getError();
                                $return = false;
                            }
                            $fileNames[] = $this->newFileName;    
                        }                    
                    }
                    $this->newFileName = $fileNames;
                }
                $this->errorMess = $errors;
                return $return;
            /*上传单个文件处理方法*/
            } else {
                /* 设置文件信息 */
                if($this->setFiles($name,$tmp_name,$size,$error)) {
                    /* 上传之前先检查一下大小和类型 */
                    if($this->checkFileSize() && $this->checkFileType()){    
                        /* 为上传文件设置新文件名 */
                        $this->setNewFileName(); 
                        /* 上传文件   返回0为成功, 小于0都为错误 */
                        if($this->copyFile()){ 
                            return true;
                        }else{
                            $return=false;
                        }
                    }else{
                        $return=false;
                    }
                } else {
                    $return=false;    
                }
                //如果$return为false, 则出错,将错误信息保存在属性errorMess中
                if(!$return)
                    $this->errorMess=$this->getError();   

                return $return;
            }
        }

        /** 
         * 获取上传后的文件名称
         * @param    void     没有参数
         * @return    string     上传后,新文件的名称, 如果是多文件上传返回数组
         */
        public function getFileName(){
            return $this->newFileName;
        }

        /**
         * 上传失败后,调用该方法则返回,上传出错信息
         * @param    void     没有参数
         * @return    string      返回上传文件出错的信息报告,如果是多文件上传返回数组
         */
        public function getErrorMsg(){
            return $this->errorMess;
        }
        
        /* 设置上传出错信息 */
        private function getError() {
            $str = "上传文件<font color="red">{$this->originName}</font>时出错 : ";
            switch ($this->errorNum) {
                case 4: $str .= "没有文件被上传"; break;
                case 3: $str .= "文件只有部分被上传"; break;
                case 2: $str .= "上传文件的大小超过了HTML表单中MAX_FILE_SIZE选项指定的值"; break;
                case 1: $str .= "上传的文件超过了php.ini中upload_max_filesize选项限制的值"; break;
                case -1: $str .= "未允许类型"; break;
                case -2: $str .= "文件过大,上传的文件不能超过{$this->maxsize}个字节"; break;
                case -3: $str .= "上传失败"; break;
                case -4: $str .= "建立存放上传文件目录失败,请重新指定上传目录"; break;
                case -5: $str .= "必须指定上传文件的路径"; break;
                default: $str .= "未知错误";
            }
            return $str.'<br>';
        }

        /* 设置和$_FILES有关的内容 */
        private function setFiles($name="", $tmp_name="", $size=0, $error=0) {
            $this->setOption('errorNum', $error);
            if($error)
                return false;
            $this->setOption('originName', $name);
            $this->setOption('tmpFileName',$tmp_name);
            $aryStr = explode(".", $name);
            $this->setOption('fileType', strtolower($aryStr[count($aryStr)-1]));
            $this->setOption('fileSize', $size);
            return true;
        }
    
        /* 为单个成员属性设置值 */
        private function setOption($key, $val) {
            $this->$key = $val;
        }

        /* 设置上传后的文件名称 */
        private function setNewFileName() {
            if ($this->israndname) {
                $this->setOption('newFileName', $this->proRandName());    
            } else{ 
                $this->setOption('newFileName', $this->originName);
            } 
        }
         
        /* 检查上传的文件是否是合法的类型 */
        private function checkFileType() {
            if (in_array(strtolower($this->fileType), $this->allowtype)) {
                return true;
            }else {
                $this->setOption('errorNum', -1);
                return false;
            }
        }
        
        /* 检查上传的文件是否是允许的大小 */
        private function checkFileSize() {
            if ($this->fileSize > $this->maxsize) {
                $this->setOption('errorNum', -2);
                return false;
            }else{
                return true;
            }
        }

        /* 检查是否有存放上传文件的目录 */
        private function checkFilePath() {
            if(empty($this->path)){
                $this->setOption('errorNum', -5);
                return false;
            }
            if (!file_exists($this->path) || !is_writable($this->path)) {
                if (!@mkdir($this->path, 0755)) {
                    $this->setOption('errorNum', -4);
                    return false;
                }
            }
            return true;
        }
        
        /* 设置随机文件名 */
        private function proRandName() {        
            $fileName = date('YmdHis')."_".rand(100,999);       
            return $fileName.'.'.$this->fileType; 
        }
        
        /* 复制上传文件到指定的位置 */
        private function copyFile() {
            if(!$this->errorNum) {
                $path = rtrim($this->path, '/').'/';
                $path .= $this->newFileName;
                if (@move_uploaded_file($this->tmpFileName, $path)) {
                    return true;
                }else{
                    $this->setOption('errorNum', -3);
                    return false;
                }
            } else {
                return false;
            }
        }
    }</code>

回复内容:

使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

 $uploadImg= new FileUpload;
                  if($uploadImg ->upload("head")){
                    echo '<pre class="brush:php;toolbar:false">';
                    var_dump($uploadImg ->getFileName());
                    echo '
'; }else{ echo '
';
                    var_dump($uploadImg ->getErrorMsg());
                    echo '
'; }
<code>                  <?php class FileUpload {    
        private $path = "./uploads";                          //上传文件保存的路径
        private $allowtype = array('jpg','jpeg','gif','png');     //设置限制上传文件的类型
        private $maxsize = 1000000;                      //限制文件上传大小(字节)
        private $israndname = true;                       //设置是否随机重命名文件, false不随机
        
        private $originName;                                //源文件名
        private $tmpFileName;                            //临时文件名
        private $fileType;                                  //文件类型(文件后缀)
        private $fileSize;                               //文件大小
        private $newFileName;                               //新文件名
        private $errorNum = 0;                            //错误号
        private $errorMess="";                           //错误报告消息
        
        /**
         * 用于设置成员属性($path, $allowtype,$maxsize, $israndname)
         * 可以通过连贯操作一次设置多个属性值
         *@param    string    $key    成员属性名(不区分大小写)
         *@param    mixed    $val    为成员属性设置的值
         *@return    object            返回自己对象$this,可以用于连贯操作
         */
        function set($key, $val){
            $key = strtolower($key); 
            if( array_key_exists( $key, get_class_vars(get_class($this) ) ) ){
                $this->setOption($key, $val);
            }
            return $this;
        }

        /**
         * 调用该方法上传文件
         * @param    string    $fileFile    上传文件的表单名称 
         * @return    bool                 如果上传成功返回数true 
         */
        
        function upload($fileField) {
            $return = true;
            /* 检查文件路径是滞合法 */
            if( !$this->checkFilePath() ) {                
                $this->errorMess = $this->getError();
                return false;
            }
            /* 将文件上传的信息取出赋给变量 */
            $name = $_FILES[$fileField]['name'];
            $tmp_name = $_FILES[$fileField]['tmp_name'];
            $size = $_FILES[$fileField]['size'];
            $error = $_FILES[$fileField]['error'];

            /* 如果是多个文件上传则$file["name"]会是一个数组 */
            if(is_Array($name)){          
                $errors=array();
                /*多个文件上传则循环处理 , 这个循环只有检查上传文件的作用,并没有真正上传 */
                for($i = 0; $i setFiles($name[$i],$tmp_name[$i],$size[$i],$error[$i] )) {
                        if(!$this->checkFileSize() || !$this->checkFileType()){
                            $errors[] = $this->getError();
                            $return=false;    
                        }
                    }else{
                        $errors[] = $this->getError();
                        $return=false;
                    }
                    /* 如果有问题,则重新初使化属性 */
                    if(!$return)                      
                        $this->setFiles();
                }
            
                if($return){
                    /* 存放所有上传后文件名的变量数组 */
                    $fileNames = array();               
                    /* 如果上传的多个文件都是合法的,则通过销魂循环向服务器上传文件 */
                    for($i = 0; $i setFiles($name[$i], $tmp_name[$i], $size[$i], $error[$i] )) {
                            $this->setNewFileName(); 
                            if(!$this->copyFile()){
                                $errors[] = $this->getError();
                                $return = false;
                            }
                            $fileNames[] = $this->newFileName;    
                        }                    
                    }
                    $this->newFileName = $fileNames;
                }
                $this->errorMess = $errors;
                return $return;
            /*上传单个文件处理方法*/
            } else {
                /* 设置文件信息 */
                if($this->setFiles($name,$tmp_name,$size,$error)) {
                    /* 上传之前先检查一下大小和类型 */
                    if($this->checkFileSize() && $this->checkFileType()){    
                        /* 为上传文件设置新文件名 */
                        $this->setNewFileName(); 
                        /* 上传文件   返回0为成功, 小于0都为错误 */
                        if($this->copyFile()){ 
                            return true;
                        }else{
                            $return=false;
                        }
                    }else{
                        $return=false;
                    }
                } else {
                    $return=false;    
                }
                //如果$return为false, 则出错,将错误信息保存在属性errorMess中
                if(!$return)
                    $this->errorMess=$this->getError();   

                return $return;
            }
        }

        /** 
         * 获取上传后的文件名称
         * @param    void     没有参数
         * @return    string     上传后,新文件的名称, 如果是多文件上传返回数组
         */
        public function getFileName(){
            return $this->newFileName;
        }

        /**
         * 上传失败后,调用该方法则返回,上传出错信息
         * @param    void     没有参数
         * @return    string      返回上传文件出错的信息报告,如果是多文件上传返回数组
         */
        public function getErrorMsg(){
            return $this->errorMess;
        }
        
        /* 设置上传出错信息 */
        private function getError() {
            $str = "上传文件<font color="red">{$this->originName}</font>时出错 : ";
            switch ($this->errorNum) {
                case 4: $str .= "没有文件被上传"; break;
                case 3: $str .= "文件只有部分被上传"; break;
                case 2: $str .= "上传文件的大小超过了HTML表单中MAX_FILE_SIZE选项指定的值"; break;
                case 1: $str .= "上传的文件超过了php.ini中upload_max_filesize选项限制的值"; break;
                case -1: $str .= "未允许类型"; break;
                case -2: $str .= "文件过大,上传的文件不能超过{$this->maxsize}个字节"; break;
                case -3: $str .= "上传失败"; break;
                case -4: $str .= "建立存放上传文件目录失败,请重新指定上传目录"; break;
                case -5: $str .= "必须指定上传文件的路径"; break;
                default: $str .= "未知错误";
            }
            return $str.'<br>';
        }

        /* 设置和$_FILES有关的内容 */
        private function setFiles($name="", $tmp_name="", $size=0, $error=0) {
            $this->setOption('errorNum', $error);
            if($error)
                return false;
            $this->setOption('originName', $name);
            $this->setOption('tmpFileName',$tmp_name);
            $aryStr = explode(".", $name);
            $this->setOption('fileType', strtolower($aryStr[count($aryStr)-1]));
            $this->setOption('fileSize', $size);
            return true;
        }
    
        /* 为单个成员属性设置值 */
        private function setOption($key, $val) {
            $this->$key = $val;
        }

        /* 设置上传后的文件名称 */
        private function setNewFileName() {
            if ($this->israndname) {
                $this->setOption('newFileName', $this->proRandName());    
            } else{ 
                $this->setOption('newFileName', $this->originName);
            } 
        }
         
        /* 检查上传的文件是否是合法的类型 */
        private function checkFileType() {
            if (in_array(strtolower($this->fileType), $this->allowtype)) {
                return true;
            }else {
                $this->setOption('errorNum', -1);
                return false;
            }
        }
        
        /* 检查上传的文件是否是允许的大小 */
        private function checkFileSize() {
            if ($this->fileSize > $this->maxsize) {
                $this->setOption('errorNum', -2);
                return false;
            }else{
                return true;
            }
        }

        /* 检查是否有存放上传文件的目录 */
        private function checkFilePath() {
            if(empty($this->path)){
                $this->setOption('errorNum', -5);
                return false;
            }
            if (!file_exists($this->path) || !is_writable($this->path)) {
                if (!@mkdir($this->path, 0755)) {
                    $this->setOption('errorNum', -4);
                    return false;
                }
            }
            return true;
        }
        
        /* 设置随机文件名 */
        private function proRandName() {        
            $fileName = date('YmdHis')."_".rand(100,999);       
            return $fileName.'.'.$this->fileType; 
        }
        
        /* 复制上传文件到指定的位置 */
        private function copyFile() {
            if(!$this->errorNum) {
                $path = rtrim($this->path, '/').'/';
                $path .= $this->newFileName;
                if (@move_uploaded_file($this->tmpFileName, $path)) {
                    return true;
                }else{
                    $this->setOption('errorNum', -3);
                    return false;
                }
            } else {
                return false;
            }
        }
    }</code>

问题解决了。在from表单少写了一个data属性

你的$this->fileType 在哪赋值的

你在 new FileUpload 之后没有设置过所允许的文件类型(扩展名),所以默认的为 'jpg','jpeg','gif','png'.

然后你所反馈的出错信息为: 未允许类型, 在代码中对应的是 errorNum 等于 -1 的情况.

使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

然后查找 设置为 -1 时的代码如下:

使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

所以结合目前的代码,得出的结论为:你在上传的时候,上传的文件扩展名不在默认允许的范围内.
即: in_array(strtolower($this->fileType), $this->allowtype) 这个条件检测失败.


根据你提供的代码, 本地测试的效果如下:
上传时选择的文件为 QQ截图20151112092309.png
使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

上传时选择的文件为 sina.html

使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

使用php的图片上传类进行图片上传,总是提示:上传文件时出错 : 未允许类型 。都是默认的配置

附完整的测试代码:

<?php
    
    class FileUpload {
        private $path = "./uploads";                          //上传文件保存的路径
        private $allowtype = array('jpg','jpeg','gif','png');     //设置限制上传文件的类型
        private $maxsize = 1000000;                      //限制文件上传大小(字节)
        private $israndname = true;                       //设置是否随机重命名文件, false不随机
        
        private $originName;                                //源文件名
        private $tmpFileName;                            //临时文件名
        private $fileType;                                  //文件类型(文件后缀)
        private $fileSize;                               //文件大小
        private $newFileName;                               //新文件名
        private $errorNum = 0;                            //错误号
        private $errorMess="";                           //错误报告消息
        
        /**
         * 用于设置成员属性($path, $allowtype,$maxsize, $israndname)
         * 可以通过连贯操作一次设置多个属性值
         *@param    string    $key    成员属性名(不区分大小写)
         *@param    mixed    $val    为成员属性设置的值
         *@return    object            返回自己对象$this,可以用于连贯操作
         */
        function set($key, $val){
            $key = strtolower($key); 
            if( array_key_exists( $key, get_class_vars(get_class($this) ) ) ){
                $this->setOption($key, $val);
            }
            return $this;
        }

        /**
         * 调用该方法上传文件
         * @param    string    $fileFile    上传文件的表单名称 
         * @return    bool                 如果上传成功返回数true 
         */
        
        function upload($fileField) {
            $return = true;
            /* 检查文件路径是滞合法 */
            if( !$this->checkFilePath() ) {                
                $this->errorMess = $this->getError();
                return false;
            }
            /* 将文件上传的信息取出赋给变量 */
            $name = $_FILES[$fileField]['name'];
            $tmp_name = $_FILES[$fileField]['tmp_name'];
            $size = $_FILES[$fileField]['size'];
            $error = $_FILES[$fileField]['error'];

            /* 如果是多个文件上传则$file["name"]会是一个数组 */
            if(is_Array($name)){          
                $errors=array();
                /*多个文件上传则循环处理 , 这个循环只有检查上传文件的作用,并没有真正上传 */
                for($i = 0; $i < count($name); $i++){ 
                    /*设置文件信息 */
                    if($this->setFiles($name[$i],$tmp_name[$i],$size[$i],$error[$i] )) {
                        if(!$this->checkFileSize() || !$this->checkFileType()){
                            $errors[] = $this->getError();
                            $return=false;    
                        }
                    }else{
                        $errors[] = $this->getError();
                        $return=false;
                    }
                    /* 如果有问题,则重新初使化属性 */
                    if(!$return)                      
                        $this->setFiles();
                }
            
                if($return){
                    /* 存放所有上传后文件名的变量数组 */
                    $fileNames = array();               
                    /* 如果上传的多个文件都是合法的,则通过销魂循环向服务器上传文件 */
                    for($i = 0; $i < count($name);  $i++){ 
                        if($this->setFiles($name[$i], $tmp_name[$i], $size[$i], $error[$i] )) {
                            $this->setNewFileName(); 
                            if(!$this->copyFile()){
                                $errors[] = $this->getError();
                                $return = false;
                            }
                            $fileNames[] = $this->newFileName;    
                        }                    
                    }
                    $this->newFileName = $fileNames;
                }
                $this->errorMess = $errors;
                return $return;
            /*上传单个文件处理方法*/
            } else {
                /* 设置文件信息 */
                if($this->setFiles($name,$tmp_name,$size,$error)) {
                    /* 上传之前先检查一下大小和类型 */
                    if($this->checkFileSize() && $this->checkFileType()){    
                        /* 为上传文件设置新文件名 */
                        $this->setNewFileName(); 
                        /* 上传文件   返回0为成功, 小于0都为错误 */
                        if($this->copyFile()){ 
                            return true;
                        }else{
                            $return=false;
                        }
                    }else{
                        $return=false;
                    }
                } else {
                    $return=false;    
                }
                //如果$return为false, 则出错,将错误信息保存在属性errorMess中
                if(!$return)
                    $this->errorMess=$this->getError();   

                return $return;
            }
        }

        /** 
         * 获取上传后的文件名称
         * @param    void     没有参数
         * @return    string     上传后,新文件的名称, 如果是多文件上传返回数组
         */
        public function getFileName(){
            return $this->newFileName;
        }

        /**
         * 上传失败后,调用该方法则返回,上传出错信息
         * @param    void     没有参数
         * @return    string      返回上传文件出错的信息报告,如果是多文件上传返回数组
         */
        public function getErrorMsg(){
            return $this->errorMess;
        }
        
        /* 设置上传出错信息 */
        private function getError() {
            $str = "上传文件<font color='red'>{$this->originName}</font>时出错 : ";
            switch ($this->errorNum) {
                case 4: $str .= "没有文件被上传"; break;
                case 3: $str .= "文件只有部分被上传"; break;
                case 2: $str .= "上传文件的大小超过了HTML表单中MAX_FILE_SIZE选项指定的值"; break;
                case 1: $str .= "上传的文件超过了php.ini中upload_max_filesize选项限制的值"; break;
                case -1: $str .= "未允许类型"; break;
                case -2: $str .= "文件过大,上传的文件不能超过{$this->maxsize}个字节"; break;
                case -3: $str .= "上传失败"; break;
                case -4: $str .= "建立存放上传文件目录失败,请重新指定上传目录"; break;
                case -5: $str .= "必须指定上传文件的路径"; break;
                default: $str .= "未知错误";
            }
            return $str.'<br>';
        }

        /* 设置和$_FILES有关的内容 */
        private function setFiles($name="", $tmp_name="", $size=0, $error=0) {
            $this->setOption('errorNum', $error);
            if($error)
                return false;
            $this->setOption('originName', $name);
            $this->setOption('tmpFileName',$tmp_name);
            $aryStr = explode(".", $name);
            $this->setOption('fileType', strtolower($aryStr[count($aryStr)-1]));
            $this->setOption('fileSize', $size);
            return true;
        }
    
        /* 为单个成员属性设置值 */
        private function setOption($key, $val) {
            $this->$key = $val;
        }

        /* 设置上传后的文件名称 */
        private function setNewFileName() {
            if ($this->israndname) {
                $this->setOption('newFileName', $this->proRandName());    
            } else{ 
                $this->setOption('newFileName', $this->originName);
            } 
        }
         
        /* 检查上传的文件是否是合法的类型 */
        private function checkFileType() {
            if (in_array(strtolower($this->fileType), $this->allowtype)) {
                return true;
            }else {
                $this->setOption('errorNum', -1);
                return false;
            }
        }
        
        /* 检查上传的文件是否是允许的大小 */
        private function checkFileSize() {
            if ($this->fileSize > $this->maxsize) {
                $this->setOption('errorNum', -2);
                return false;
            }else{
                return true;
            }
        }

        /* 检查是否有存放上传文件的目录 */
        private function checkFilePath() {
            if(empty($this->path)){
                $this->setOption('errorNum', -5);
                return false;
            }
            if (!file_exists($this->path) || !is_writable($this->path)) {
                if (!@mkdir($this->path, 0755)) {
                    $this->setOption('errorNum', -4);
                    return false;
                }
            }
            return true;
        }
        
        /* 设置随机文件名 */
        private function proRandName() {        
            $fileName = date('YmdHis')."_".rand(100,999);       
            return $fileName.'.'.$this->fileType; 
        }
        
        /* 复制上传文件到指定的位置 */
        private function copyFile() {
            if(!$this->errorNum) {
                $path = rtrim($this->path, '/').'/';
                $path .= $this->newFileName;
                if (@move_uploaded_file($this->tmpFileName, $path)) {
                    return true;
                }else{
                    $this->setOption('errorNum', -3);
                    return false;
                }
            } else {
                return false;
            }
        }
    }

if(isset($_GET['upload'])){
    $uploadImg= new FileUpload;
    if($uploadImg->upload("head")){
        echo '<pre class="brush:php;toolbar:false">';
        var_dump($uploadImg ->getFileName());
        echo '
'; }else{ echo '
';
        var_dump($uploadImg ->getErrorMsg());
        echo '
'; } } ?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft