2016-10-28 2 views
0

ドロップゾーンにファイルを保存するボタンがあります。ドロップゾーンにアップロードするファイルがdropzoneにある場合は自動的にフォルダに移動し、ボタンを押すと保存するファイル名はmysqlに保存されますデータ。今問題は、私は自分のファイルをリセットしたい場合は、私はページを更新するか、私はボタンを保存する前にページを閉じてdropzoneを取得する?それは不可能ですか? ここに私のコード! jQueryのウィンドウがリフレッシュまたは閉じるときにリセットする

Dropzone.options.dropZone = { 
      //options here 
      maxFilesize: 1, 
      addRemoveLinks: true, 
      removedfile: function(file) { 
       var name = file.name;   
       $.ajax({ 
        type: 'POST', 
        url: host+'upload/unfile', 
        data: "id="+name, 
        dataType: 'html' 
       }); 
       var _ref; 
       return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0; 

       //console.log(); 
      } 

     } 

HTMLで

<div class="dropzone form-control input-sm" action="<?php echo SERVER_NAME; ?>upload/file" id="dropZone"> 
          <div class="fallback" > 
           <input type="file" name="file" id="file"/> 
          </div> 
         </div> 

contorler

public function file(){ 
      if (!empty($_FILES)) { 
       $tempFile = $_FILES['file']['tmp_name']; 
       $fileName = $_FILES['file']['name']; 
       $fileType = $_FILES['file']['type']; 
       $fileSize = $_FILES['file']['size']; 
       $targetPath = './public/uploads/'; 
       $targetFile = $targetPath . $fileName ; 

       //var_dump($_FILES); 
       move_uploaded_file($tempFile, $targetFile); 
      } 
     } 

     public function unfile() { 
      $fileName = $_POST["id"]; 
      //var_dump($fileName); 
      $targetPath = './public/uploads/'; 
      $targetFile = $targetPath . $fileName ; 
      unlink($targetFile); 

     } 

NOTE上:リフレッシュ/クローズページアップロードされたファイルはありませんが、MySQLが削除されます保存するときに私が必要私のフォルダに。

答えて

0

ネヴァーマインド私はこのコードを使用し、prefectly私のファイルを削除:)

$(window).on('beforeunload', function(){ 
       return 'Are you sure you want to leave? Warning!!! Data is still progress will not be saved'; 
     }); 

     $(window).on('unload', function(){ 
       var file = $('.dropzone .dz-preview').children().find('.dz-filename').find('span').html();      
       $.ajax({ 
        type: 'POST', 
        url: host+'upload/unfile', 
        data: "id="+file, 
        dataType: 'html', 
        async : false 
       }); 
       //alert('Your Out!!'); 
     }); 

ない私はドロップゾーンで午前のように、誰かが問題を抱えている場合はuがいるので、重要なasync : falseを使用する必要があり、それを見つけました!

関連する問題