警告:move_uploaded_file()错误并且无法在面向PHP的对象中移动文件

时间:2019-06-26 08:31:14

标签: php

我正在尝试使用php oops上传图像,但是每次使用move_uploaded_file()时,我都会不断收到错误消息。

点击提交

if(is_post_request()) {
  // Create record using post parameters
  $args = $_POST['project'];
  $project = new Project($args);
  $project->set_file($_FILES['project_images']);
  $result = $project->save_photo();

  if($result === true) {
    $new_id = $project->id;
    $session->message('The Project was created successfully.');    
  }

设置文件功能

public $tmp_path;
public $upload_directory = "image";

 public function set_file($file) {

  if(empty($file) || !$file || !is_array($file)){

    $this->errors[] = "There was no file uploaded here";
    return false;

  }
  elseif($file['error'] !=0) {
    $this->errors[] = $this->upload_errors_array[$file['error']];
    return false;
  }
  else {

    $this->project_name = basename($file['name']);
    $this->tmp_path = $file['tmp_name'];

  }
}

保存功能

public  function save_photo() {

   if($this->id){
     $this->update();
   }
   else{

     if(!empty($this->errors)){
       return false;
     }

     if(empty($this->project_name) || empty($this->tmp_path)){ 
       $this->errors[] = "The File was not available";
       return false;
     }


     $target_path = SITE_ROOT . DS . 'admin' .DS. $this->$upload_directory .DS. $this->project_name;// This is line 116

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

     if(move_uploaded_file($this->tmp_path, $target_path)){ //This is line 123
       if($this->create()){
         unset($this->tmp_path);
         return true;
       }
       else {
         $this->errors[] = "The file directory probably does not have permission";
         return false;
       }
     }
   }
}
  

警告:move_uploaded_file(\ Applications \ XAMP \ htdocs \ project \ admin \ pos deatils.png):无法打开流:C:\ xamp \ htdocs \ project \ private \ classes \ project中没有此类文件或目录。第123行的class.php

     

警告:move_uploaded_file():无法将C:\ xamp \ tmp \ phpB5A0.tmp'移动到C:\ xamp \ htdocs \中的'\ Applications \ XAMP \ htdocs \ project \ admin \ pos deatils.png'第123行的project \ private \ classes \ project.class.php

     

未定义的属性:第116行的C:\ xamp \ htdocs \ project \ private \ classes \ project.class.php中的Project :: $

0 个答案:

没有答案