【问题标题】:File upload error cakephp文件上传错误 cakephp
【发布时间】:2010-01-11 22:50:27
【问题描述】:

当我选择图像并推送上传时,我的控制器中出现此错误: 注意(8):未定义索引:文件[APP/controllers/garage_car_images_controller.php,第22行]

我还注意到下面显示的 $form->create 行不会在检查的 html 中生成表单代码。这很奇怪。

任何想法如何解决这个问题?谢谢!

我的查看代码:

<div class="title_plate">
    <h1 id="title_plate_header">add image</h1>
</div>
<div id="overlay_content">
<?php
    echo $form->create('GarageCarImage', array('controller' => 'garage_car_images','action' => 'add', 'type' => 'file'));
    echo $form->file('File');
    echo $form->hidden('garage_car_id', array('value' => $this->params['pass'][0]));
    echo "<br><br>";
    echo "Make this image the default? " . $form->input('default', array('type' => 'select', 'label' => false, 'options' => array('0' => 'No', '1' => 'Yes')));
    echo "<br>";
    echo $form->submit('Upload');
    echo $form->end();
?>
</div>

我的控制器代码:

if (!empty($this->data) &&
             is_uploaded_file($this->data['GarageCarImage']['File']['tmp_name'])) {
            $fileData = fread(fopen($this->data['GarageCarImage']['File']['tmp_name'], "r"),
                                     $this->data['GarageCarImage']['File']['size']);

            $this->data['GarageCarImage']['type'] = $this->data['GarageCarImage']['File']['type'];
            $this->data['GarageCarImage']['user_id'] = $this->Auth->user('id');
            $this->GarageCarImage->save($this->data);
}

【问题讨论】:

  • 选择您发布的代码并点击“01 10”按钮(代码)...它将格式化代码以便在此处查看。
  • 01 10 按钮是什么意思?
  • 知道了...我按照你的要求做了:)

标签: file cakephp forms upload indexing


【解决方案1】:

您确定它不会生成表单代码吗?如果没有,我认为您甚至无法尝试提交表单。我相信提交表单是因为您似乎发出了对 /garageCarImages/index 的请求——对我来说,这表明表单正在正确生成。

如果确实如此,您只需将第一个参数的值更改为您希望代码在其中执行的控制器的名称。对我来说,通常我使用附件控制器来执行此操作,所以我会说:

echo $form->create( 'Attachment', array(...) );

您的情况将取决于处理上传的代码所在的位置。很可能是 ImageController(在这里猜测...),但如果不了解您的系统的更多详细信息,我不确定。

【讨论】:

    猜你喜欢
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-14
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 2011-04-24
    相关资源
    最近更新 更多