0

从昨天开始,我尝试在我的项目中实现多个文件上传,数据库使用新文件名更新,但文件没有上传(到本地主机)。

所以我的观点现在是这样的:

<?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();
}}

也许你们中的一些人已经知道这个问题并且可以给我一个提示?

4

1 回答 1

0

所以我只是禁用了 FileUploadComponent 并插入

if ($exists) {
    continue;
} else {
--> move_uploaded_file($row['tmp_name'], WWW_ROOT . 'files/' . $row['name']);
    $this->Upload->create();
    $this->Upload->set('name', $row['name']);
    $this->Upload->set('type', $row['type']);
    $this->Upload->set('size', $row['size']);
    $this->Upload->save();
}

现在它工作正常:)

于 2014-10-28T06:02:32.697 回答