【问题标题】:issues in image uploading with php codeigniter使用 php codeigniter 上传图片的问题
【发布时间】:2016-07-05 11:56:53
【问题描述】:

我在使用 php codeigniter 上传图片时遇到了一些问题。

这是我的控制器

 public function FunctionName()
  {

        $profile_pic  = $this->input->post('profile_pic');
        echo $profile_pic;         

  }

这是一个简单的功能,我只想查看我选择的文件(图像)的名称。

这是我的看法

<form class="" method="post" action="<?=base_url();?>Controller/FunctionName" enctype="multipart/form-data">

    <input type="file" name="profile_pic">

    <input type="submit" name="submit">

    </form>

当我运行这个脚本时。它向我显示了一个空白页。我无法获取/显示我选择的文件的名称。请注意,我已经自动加载了帮助程序。例如。

$autoload['helper'] = array('url', 'file', 'date', 'form');

【问题讨论】:

  • 使用 echo $_FILES['profile_pic'][name];
  • 它给了我错误:消息:使用未定义的常量名称 - 假定为“名称”
  • 我的错误试试这个。使用 echo $_FILES['profile_pic'];
  • 现在它显示字符串'Array'而不是文件名,并且它还给出错误:消息:数组到字符串转换

标签: php codeigniter file-upload


【解决方案1】:
$file=$_FILES['file_name']['name'];
$config =         array('file_name'=>$file,
                        'upload_path' => "./folder/",
                        'allowed_types' => "jpg|jpeg|png",
                        'remove_spaces' => FALSE,
                        'overwrite' => TRUE
                                        );

                    $this->load->library('upload', $config);
                    $this->upload->do_upload('file_name');

【讨论】:

  • 它有效。多谢。我需要你的进一步帮助。现在我想将原始文件名更改为另一个名称,例如“myname_2016”,并希望将这个新名称存储在数据库中。请帮帮我。
  • 只使用数组('file_name'=>'myname_2016')
  • 我可以将其存储在外部变量(外部数组)中,以便将其发送到数据库进行插入???
  • 您可以将其存储为外部变量
  • 是的,明白了。这就是我所做的。 $varname = $config['file_name'];
猜你喜欢
  • 1970-01-01
  • 2017-02-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-28
  • 1970-01-01
相关资源
最近更新 更多