duanjigua5753 2016-09-12 08:12
浏览 152

Windows 10文件上传和权限php

I'm having trouble moving uploaded files, the problem seems to be a permissions problem, any help would be much appreciated. I'm using windows 10 and I've change my temp folder in php.ini to a custom folder in xampp directory and when I check this temp folder the file isn't there either, so it seems that it isn't even being uploaded to them temp. Please help.

class PortfolioItem extends DataBaseCommonObj{

protected static $table_name = 'portfolio_item';
protected static $db_fields = array('id','filename','mimetype','size','caption','job_id');

public $id;
public $filename;
public $mimetype;
public $size;
public $caption;
public $job_id;


private $temp_path;
protected $upload_dir="_portfolio-items";
public $errors=array();

protected $upload_errors = array(
  // http://www.php.net/manual/en/features.file-upload.errors.php
  UPLOAD_ERR_OK                 => "No errors.",
  UPLOAD_ERR_INI_SIZE   => "Larger than upload_max_filesize.",
  UPLOAD_ERR_FORM_SIZE  => "Larger than form MAX_FILE_SIZE.",
  UPLOAD_ERR_PARTIAL        => "Partial upload.",
  UPLOAD_ERR_NO_FILE        => "No file.",
  UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
  UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
  UPLOAD_ERR_EXTENSION  => "File upload stopped by extension."
);

public function attach_file($file){
  global $session;
  if(!$file || empty($file) || !is_array($file)){
    $this->errors[] = 'no file was uploaded';
    return false;
  }elseif ($file['error'] != 0) {
    $this->errors[]=$this->upload_errors[$file['error']];
    return false;
  }else {
    $this->filename = basename($file['name']);
    $this->temp_path = $file['tmp_name'];
    $this->mimetype = $file['type'];
    $this->size = $file['size'];

    if(isset($session->message) && $session->message !== ''){
      $current_job = Job::find_by_id(intval($session->message));
      $this->job_id = $current_job->id;
    }
    return true;
  }
}


defined('DS')?null:define('DS',DIRECTORY_SEPARATOR);
defined('SITE_ROOT')?null:define('SITE_ROOT', DS.'mp_creations');
defined('INC_PATH')?null:define('INC_PATH', SITE_ROOT.DS.'includes');
defined('PUB_PATH')?null:define('PUB_PATH', SITE_ROOT.DS.'public');


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

    if(empty($this->filename) || empty($this->temp_path)){
      $this->errors[] = 'file path not available';
      return false;
    }

    $target_path = PUB_PATH.DS.$this->upload_dir.DS.$this->filename;

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

    if(move_uploaded_file($this->temp_path,$target_path)){
      if($this->create()){
        unset($this->temp_path);
        return true;
      }
    }else {
      $this->errors[]='The file upload failed, possibly due to permission issues';
      return false;
    }
  }
}
  • 写回答

2条回答 默认 最新

  • dtx9931 2016-09-12 08:20
    关注

    The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

    http://php.net/manual/en/features.file-upload.post-method.php
    
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况