2014-07-11 42 views
0

我的問題是我想整合dropzone和cakephp 2.5;但表格提交後 $ this-> request-> data ['pic']返回空數組。但是在添加圖像時在放置區域中;它顯示了成功的形象。第二;文件沒有移動到目標路徑「APP.'webroot'.DS.'uploadedpics'.DSdropzone with cakephp 2.5

請看看下面我的代碼。在默認佈局

我已經包含了懸浮窗CSS和JS文件

echo $this->Html->css('dropzone/basic'); 
echo $this->Html->css('dropzone/dropzone'); 

echo $this->Html->script('js/dropzone/dropzone'); 
echo $this->Html->script('js/dropzone/dropzone.min'); 
echo $this->Html->script('js/dropzone/dropzone-amd-module'); 
echo $this->Html->script('js/dropzone/dropzone-amd-module.min'); 

我的HTML頁面具有形式和懸浮窗JS: -

<form method="post" action="/domain/controller/addpics" class="dropzone" id="mydropzone" enctype='multipart/form-data'> 
<div id="dropzonePreview"></div> <!--// this will the dropzone drag and drop section .notice we have given it an id dropzonePreview .--> 
<input type="button" id="sbmtbtn" value="submit"/> 
</form> 

<script> 
Dropzone.options.mydropzone = { 
// url does not has to be written if we have wrote action in the form tag but i have mentioned here just for convenience sake 
url: '/domain/controller/addpics', 
addRemoveLinks: true, 
autoProcessQueue: false, // this is important as you dont want form to be submitted unless you have clicked the submit button 
autoDiscover: false, 
paramName: 'pic', // this is optional Like this one will get accessed in php by writing $_FILE['pic'] // if you dont specify it then bydefault it taked 'file' as paramName eg: $_FILE['file'] 
previewsContainer: '#dropzonePreview', // we specify on which div id we must show the files 
clickable: false, // this tells that the dropzone will not be clickable . we have to do it because v dont want the whole form to be clickable 
accept: function(file, done) { 
console.log("uploaded"); 
done(); 
}, 
error: function(file, msg){ 
alert(msg); 
}, 
init: function() { 

var myDropzone = this; 
//now we will submit the form when the button is clicked 
$("#sbmtbtn").on('click',function(e) { 
e.preventDefault(); 
myDropzone.processQueue(); // this will submit your form to the specified action path 
// after this, your whole form will get submitted with all the inputs + your files and the php code will remain as usual 
//REMEMBER you DON'T have to call ajax or anything by yourself, dropzone will take care of that 
}); 

} // init end 

}; 
</script> 

控制器代碼: -

function addpics() { 
    $tempFile = $this->request->data['pic']['tmp_name'];   
    $targetPath = APP.'webroot'.DS.'uploadedpics'.DS; 
    $targetFile = $targetPath. $this->request->data['pic']['name']; 
    move_uploaded_file($tempFile,$targetFile); 
} 

問候

+0

你可以說得到文件的信息,如果這個爲你工作?下面的答案...... – nullwriter

+0

@CFeo:我猜測你自己試着編碼沒有什麼壞處......它應該在最慢的速度下花5分鐘...... – Fr0zenFyr

回答

1


當您使用懸浮窗,並提交表單服務器,
在控制器,你可以通過使用源作爲波紋管

$file = $this->params->form['file']; 

好運

0
APP . DS . 'webroot'.DS.'uploadedpics'.DS 
     ^--Directory Separator might be needet. 
+1

雖然這段代碼可能有助於解決問題, 提供關於_why_和/或_how_的其他上下文, 回答該問題將顯着提高其 的長期價值。請[編輯]你的答案,添加一些 的解釋。 –