昨日から、プロジェクトに複数のファイルのアップロードを実装しようとしましたが、データベースは新しいファイル名で更新されましたが、ファイルは (localhost に) アップロードされませんでした。
したがって、私のビューは次のようになります。
<?php echo $this->Form->create('Upload', array('type' => 'file')); ?>
<fieldset>
<br/>
<?php echo $this->Form->input('files.', array('type' => 'file', 'multiple' => 'multiple', 'label' => '')); ?>
</fieldset>
<?php echo $this->Form->end(__('upload'));?>`
コントローラーに foreach() を追加しました:
$files = $this->request->data['Upload']['files'];
$counter = 0;
foreach ($files as $row) {
$counter += 1;
$uploads = $this->Upload->find('all');
$exists=false;
foreach ($uploads as $upl) {
if (strcmp($upl['Upload']['name'], $row['name'])==0)
$exists=true;
}
print_r($exists);
if ($exists) {
continue;
} else {
$this->Upload->create();
$this->Upload->set('name', $row['name']);
$this->Upload->set('type', $row['type']);
$this->Upload->set('size', $row['size']);
$this->Upload->save();
}
}
if($counter > 1) {
$this->Session->setFlash(__('Files uploaded'));
} else if($exists && $counter == 1) {
$this->Session->setFlash(__('File could not be uploaded. File already exists.'));
} else {
$this->Session->setFlash(__('File uploaded'));
}
私のログでは、次のエラーが表示されます。
Warning (512): FileUpload: A file was detected, but was unable to be processed due to a misconfiguration of FileUpload. Current config -- fileModel:'Upload' fileVar:'file' [APP/Plugin/file_upload/Controller/Component/FileUploadComponent.php, line 403]
そしてもう一つ:
Warning (2): Invalid argument supplied for foreach() [APP/Plugin/file_upload/Controller/Component/FileUploadComponent.php, line 341]
私のFileUploadComponentは次のとおりです
* @link http://www.webtechnick.com
* @author Nick Baker
* @version 4.0.4
* @license MIT
FileUploadComponent の 341 行目は次のとおりです。
function processAllFiles(){
foreach($this->uploadedFiles as $file){
$this->_setCurrentFile($file);
$this->Uploader->file = $this->options['fileModel'] ? $file[$this->options['fileVar']] : $file;
$this->processFile();
}}
この問題をすでに知っている人がいて、そのヒントを教えてくれませんか?