使用 codeigniter 上传图像和文本

发布于 2024-11-29 03:20:01 字数 2063 浏览 0 评论 0原文

我正在尝试创建可以上传文本和图像的表单。但是,当我输入信息时,只会保存文本,但图像似乎不会出现在文件夹中。

我的控制器文件的一部分

               $form_data = array(
                        'address' => set_value('address'),
                        'area' => set_value('area'),
                        'lat' => set_value('lat'),
                        'lng' => set_value('lng'),
                        'subject' => set_value('subject'),
                        'problem' => set_value('problem'),
                        'image' => '',//what to put here???
                        'time' => $now,

                        'register_id' =>set_value ('register_id'),
                        'category_id' => set_value('category_id'),
                        'city_city_id' => set_value('city_city_id'),
                        'status_status_id' => set_value('status_status_id')
                    );

      if ($this->report_model->SaveForm($form_data) == TRUE) 
   {
   redirect('report/success');

            }





               function do_upload()  
            {
          $config['upload_path'] = './uploads/';

    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';
    $this->upload->initialize($config); 
    $this->load->library('upload', $config);



}

查看文件

        $attributes = array('class' => '', 'id' => '');
                 echo form_open('report', $attributes); ?>

              <p>
    <label for="problem">problem detail:</label>
    <?php echo form_error('problem'); ?>
    <br /><input id="problem" type="text" name="problem"  value="<?php echo

                set_value('problem'); ?>"  />
                   </p>

          <p>Upload a image:


            <?php echo form_open_multipart('report/do_upload');?>

               <input type="file" name="image" size="20" />

请帮忙

i'm trying to create form which with which i can upload text and image both. But when i enter the information the texts only get saved but the image doesn't seem to appear the folder.

Part of my controller file

               $form_data = array(
                        'address' => set_value('address'),
                        'area' => set_value('area'),
                        'lat' => set_value('lat'),
                        'lng' => set_value('lng'),
                        'subject' => set_value('subject'),
                        'problem' => set_value('problem'),
                        'image' => '',//what to put here???
                        'time' => $now,

                        'register_id' =>set_value ('register_id'),
                        'category_id' => set_value('category_id'),
                        'city_city_id' => set_value('city_city_id'),
                        'status_status_id' => set_value('status_status_id')
                    );

      if ($this->report_model->SaveForm($form_data) == TRUE) 
   {
   redirect('report/success');

            }





               function do_upload()  
            {
          $config['upload_path'] = './uploads/';

    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';
    $this->upload->initialize($config); 
    $this->load->library('upload', $config);



}

View file

        $attributes = array('class' => '', 'id' => '');
                 echo form_open('report', $attributes); ?>

              <p>
    <label for="problem">problem detail:</label>
    <?php echo form_error('problem'); ?>
    <br /><input id="problem" type="text" name="problem"  value="<?php echo

                set_value('problem'); ?>"  />
                   </p>

          <p>Upload a image:


            <?php echo form_open_multipart('report/do_upload');?>

               <input type="file" name="image" size="20" />

please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青巷忧颜 2024-12-06 03:20:01

默认情况下,上传的文件名为 userfile

<input type="file" name="userfile" size="20" />

将上传输入元素的 image 更改为 userfile

否则将 image 定义为上传类使用的名称/ID。

如果您想设置自己的字段名称,只需将其值传递给
do_upload 函数:

$field_name = "some_field_name";
$this->upload->do_upload($field_name)

参考: http://codeigniter.com/user_guide/ Librarys/file_uploading.html


实际上... 似乎您到处都是(多个表单?)

只需转到我提供的参考链接,然后启动一个表单,请遵循用户指南以获取最佳详细信息,我认为您只是对如何在 CI 下创建表单感到困惑。

By default the file uploaded is called userfile

<input type="file" name="userfile" size="20" />

Change that image to userfile for your upload input element.

Otherwise define image as the name/id to use by the upload class.

If you would like to set your own field name simply pass its value to
the do_upload function:

$field_name = "some_field_name";
$this->upload->do_upload($field_name)

Ref: http://codeigniter.com/user_guide/libraries/file_uploading.html


ACTUALLY... seems you are all over the place (multiple forms?)

Just go to the reference link I provided, and start a single form, follow the user guide for best details, I think you are just confusing how to create a form under CI.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文