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 に答える