Php 图像上载错误无法打开流:没有此类文件或目录,无法移动文件

Php 图像上载错误无法打开流:没有此类文件或目录,无法移动文件,php,Php,我正试图上传一张图片,但我收到下面的错误消息,我如何修复? 警告:移动上传的文件(\C:\xampp\htdocs\gallery\admin\images\91H8nDVT8dL.SL1500.jpg):无法打开流:第97行的C:\xampp\htdocs\gallery\admin\includes\photo.php中没有此类文件或目录 <?php class Photo extends Db_object { protected static $db_

我正试图上传一张图片,但我收到下面的错误消息,我如何修复? 警告:移动上传的文件(\C:\xampp\htdocs\gallery\admin\images\91H8nDVT8dL.SL1500.jpg):无法打开流:第97行的C:\xampp\htdocs\gallery\admin\includes\photo.php中没有此类文件或目录

<?php

class Photo extends Db_object {


            protected static $db_table = "photos";
            protected static $db_table_fields= array('id','title','caption','description','filename','alternate_text','type','size');
            public $id;
            public $title;
            public $caption;
            public $description;
            public $filename;
            public $alternate_text;
            public $type;
            public $size;

            public $tmp_path;
            public $upload_directory = "images";
            public $errors = array();
            public $upload_errors_array = array(


            UPLOAD_ERR_OK         => "There is no error",
            UPLOAD_ERR_INI_SIZE   => "The uploaded file exceeds the upload_max_filesize directive",
            UPLOAD_ERR_FORM_SIZE  => "The uploaded file exceeds the MAX_FILE_SIZE ",
            UPLOAD_ERR_PARTIAL    => "The uploaded file was only partially uploaded",
            UPLOAD_ERR_NO_FILE    => "No file was uploaded",
            UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder",
            UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk",
            UPLOAD_ERR_EXTENSION  => "A PHP extension stopped the file upload."



            );



            //This is passing $_FILES['uploaded_file'] as an argumnent

            public function set_file($file)
            {

                if(empty($file) || !$file || !is_array($file))
                {
                    $this->errors[] = "There was no file uploaded here";
                    return false;
                }
                else
                    if ($file['error']!=0) {
                        $this->errors[] = $this->upload_errors_array($file['error']);
                        return false;

                    }

                    else
                    {

                        $this->filename = basename($file['name']);
                        $this->tmp_path = $file['tmp_name'];
                        $this->type = $file['type'];
                        $this->size = $file['size'];
                    }
            }


            public function picture_path()
            {
                return $this->upload_directory.DS.$this->filename;
            }


            public function save(){
                    if($this->id) {
                    $this->update();
                    }
                    else
                    {
                             if(!empty($this->errors))
                                 {
                                    return false;
                                 }

                             if(empty($this->filename) || empty($this->tmp_path))
                                 {
                                     $this->errors[] = "This file was not available";
                                     return false;
                                 }

                              $target_path= SITE_ROOT .DS. 'admin' .DS. $this->upload_directory.DS. $this->filename;

                             if(file_exists($target_path))
                                 {
                                    $this->errors[]="The file {$this->filename} already exists";
                                    return false;
                                 }

                             if(move_uploaded_file($this->tmp_path, $target_path))
                                 {
                                    if($this->create())
                                        {
                                            unset($this->tmp_path);
                                            return true;
                                        }
                                 }
                             else
                                 {

                                    $this->errors[]= "The file directly probably does not have permission";
                                    return false;
                                 }
                }
            }


            public function delete_photo(){
                if($this->delete())
                {
                    $target_path=SITE_ROOT.DS. 'admin' .DS. $this->picture_path();
                    return unlink($target_path)?true: false;
                }
                else
                {
                    return false;
                }

            }


}

?>

警告:move_uploaded_file():无法将C:\xampp\tmp\php5547.tmp移动到C:\xampp\htdocs\gallery\admin\images\91H8nDVT8dL.SL1500.jpg中C:\xampp\htdocs\gallery\admin\includes\photo.php的第97行

<?php

class Photo extends Db_object {


            protected static $db_table = "photos";
            protected static $db_table_fields= array('id','title','caption','description','filename','alternate_text','type','size');
            public $id;
            public $title;
            public $caption;
            public $description;
            public $filename;
            public $alternate_text;
            public $type;
            public $size;

            public $tmp_path;
            public $upload_directory = "images";
            public $errors = array();
            public $upload_errors_array = array(


            UPLOAD_ERR_OK         => "There is no error",
            UPLOAD_ERR_INI_SIZE   => "The uploaded file exceeds the upload_max_filesize directive",
            UPLOAD_ERR_FORM_SIZE  => "The uploaded file exceeds the MAX_FILE_SIZE ",
            UPLOAD_ERR_PARTIAL    => "The uploaded file was only partially uploaded",
            UPLOAD_ERR_NO_FILE    => "No file was uploaded",
            UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder",
            UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk",
            UPLOAD_ERR_EXTENSION  => "A PHP extension stopped the file upload."



            );



            //This is passing $_FILES['uploaded_file'] as an argumnent

            public function set_file($file)
            {

                if(empty($file) || !$file || !is_array($file))
                {
                    $this->errors[] = "There was no file uploaded here";
                    return false;
                }
                else
                    if ($file['error']!=0) {
                        $this->errors[] = $this->upload_errors_array($file['error']);
                        return false;

                    }

                    else
                    {

                        $this->filename = basename($file['name']);
                        $this->tmp_path = $file['tmp_name'];
                        $this->type = $file['type'];
                        $this->size = $file['size'];
                    }
            }


            public function picture_path()
            {
                return $this->upload_directory.DS.$this->filename;
            }


            public function save(){
                    if($this->id) {
                    $this->update();
                    }
                    else
                    {
                             if(!empty($this->errors))
                                 {
                                    return false;
                                 }

                             if(empty($this->filename) || empty($this->tmp_path))
                                 {
                                     $this->errors[] = "This file was not available";
                                     return false;
                                 }

                              $target_path= SITE_ROOT .DS. 'admin' .DS. $this->upload_directory.DS. $this->filename;

                             if(file_exists($target_path))
                                 {
                                    $this->errors[]="The file {$this->filename} already exists";
                                    return false;
                                 }

                             if(move_uploaded_file($this->tmp_path, $target_path))
                                 {
                                    if($this->create())
                                        {
                                            unset($this->tmp_path);
                                            return true;
                                        }
                                 }
                             else
                                 {

                                    $this->errors[]= "The file directly probably does not have permission";
                                    return false;
                                 }
                }
            }


            public function delete_photo(){
                if($this->delete())
                {
                    $target_path=SITE_ROOT.DS. 'admin' .DS. $this->picture_path();
                    return unlink($target_path)?true: false;
                }
                else
                {
                    return false;
                }

            }


}

?>



管理员文件夹中是否有图像目录?是的,管理员文件夹中是否有图像目录。您的目标路径错误。请回音检查一下。我猜SITE_ROOT以/开头,但它不在Windows系统中,它的结构在Linux系统中。因此,您得到的错误是:admin文件夹中是否有可用的图像目录?是的,admin文件夹中是否有可用的图像目录。您的目标路径错误。请回音检查一下。我猜SITE_ROOT以/开头,但它不在Windows系统中,它的结构在Linux系统中。因此,你会犯错误