1

当我使用mkdir(). 代码工作正常。我可以上传到具有特定 ID 的已创建文件夹。当我想移动或复制或删除文件夹时,我的问题出现了,它拒绝所有操作。

有关如何获得权限的任何帮助都允许我执行这些操作

//upload function
public function import($app_id = null) {
  if ($this->request->is('post')) {
    //debug($this->data); die();
    $app_id=$this->data['Upload']['applicants_detail_id'];
    //debug($app_id); die();
    $files_dir = "c:\\xampp\\htdocs\\newstudents\\app\\myuploads\\" .$app_id." \\";
    $destination = mkdir($files_dir); //creating the directory with the app_id.
//  chmod ("$destination", 0755); 


    $filename = $files_dir . $this->request->data['Upload']['OLevel']['name'];
    if($success = move_uploaded_file($this->request->data['Upload']['OLevel']['tmp_name'],$filename)){
        for($i=0; $i < sizeof($this->request->data['Upload']['OLevel']['tmp_name']); $i++){
            $this->Upload->create();
            $this->Upload->set(array(
                'applicants_detail_id'=>$app_id,
                'caption'=> $this->request->data['Upload']['OLevel']['name'],
                'path'=>$filename,
                'doctype'=>$this->data['Upload']['Olevel']
            ));
            $this->Upload->save();
        }
    }

    $filename = $files_dir . $this->request->data['Upload']['ALevel']['name'];
    if($success = move_uploaded_file($this->request->data['Upload']['ALevel']['tmp_name'],$filename)){
        for($m=0; $m < sizeof($this->request->data['Upload']['ALevel']['tmp_name']); $m++){
            $this->Upload->create();
            $this->Upload->set(array(
                'applicants_detail_id'=>$app_id,
                'caption'=> $this->request->data['Upload']['ALevel']['name'],
                'path'=>$filename,
                'doctype'=>$this->data['Upload']['Alevel']
            ));
            $this->Upload->save();
        }
    }

    $filename = $files_dir . $this->request->data['Upload']['BirthCertificate']['name'];
    if($success = move_uploaded_file($this->request->data['Upload']['BirthCertificate']['tmp_name'],$filename)){
        for($n=0; $n < sizeof($this->request->data['Upload']['Birth']['tmp_name']); $n++){
            $this->Upload->create();
            $this->Upload->set(array(
                'applicants_detail_id'=>$app_id,
                'caption'=> $this->request->data['Upload']['BirthCertificate']['name'],
                'path'=>$filename,
                'doctype'=>$this->data['Upload']['Birth']
            ));
            $this->Upload->save();
        }
    }

    $filename = $files_dir . $this->request->data['Upload']['NationalID']['name'];
    if($success = move_uploaded_file($this->request->data['Upload']['NationalID']['tmp_name'],$filename)){
        for($k=0; $k < sizeof($this->request->data['Upload']['National_id']['tmp_name']); $k++){
            $this->Upload->create();
            $this->Upload->set(array(
                'applicants_detail_id'=>$app_id,
                'caption'=> $this->request->data['Upload']['NationalID']['name'],
                'path'=>$filename,
                'doctype'=>$this->data['Upload']['National_id']
            ));
            $this->Upload->save();
        }
    }

    $filename = $files_dir . $this->request->data['Upload']['OtherCertificate']['name'];
    if($success = move_uploaded_file($this->request->data['Upload']['OtherCertificate']['tmp_name'],$filename)){
        for($x=0; $x < sizeof($this->request->data['Upload']['OtherCertificate']['tmp_name']); $x++){
            $this->Upload->create();
            $this->Upload->set(array(
                'applicants_detail_id'=>$app_id,
                'caption'=> $this->request->data['Upload']['OtherCertificate']['name'],
                'path'=>$filename,
                'doctype'=>$this->data['Upload']['other']
            ));
            $this->Upload->save();
        }
    }
4

1 回答 1

0

我建议使用 API 来操作目录和文件。并且使用正确的CakePHP目录结构,您的文件应该在webroot目录中。

而是mkdir()用于创建:

$files_dir = APP . WEBROOT_DIR . DS . "myuploads" . DS . $app_id;
$destination = new Folder($files_dir, true, 0755);

参考:

于 2012-07-04T13:48:45.943 回答