Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用随机唯一名称和数据库上载路径更新图像不起作用_Php_Mysql_Codeigniter - Fatal编程技术网

Php 使用随机唯一名称和数据库上载路径更新图像不起作用

Php 使用随机唯一名称和数据库上载路径更新图像不起作用,php,mysql,codeigniter,Php,Mysql,Codeigniter,我正在使用codeigniter,我想用随机唯一名称更新图像,用数据库上传路径,但不工作 我想用codeigniter更新图像,但效果不好。我正在共享代码模型。 tabel name dpr_user和field name user_pic 表单视图 表单查看页面工作正常这里是我使用的代码模型表单 <form method="post" action="<?php echo base_url() ?>update_picture" enctype="multipart/

我正在使用codeigniter,我想用随机唯一名称更新图像,用数据库上传路径,但不工作

我想用codeigniter更新图像,但效果不好。我正在共享代码模型。 tabel name dpr_user和field name user_pic

表单视图

表单查看页面工作正常这里是我使用的代码模型表单

    <form method="post" action="<?php echo base_url() ?>update_picture" enctype="multipart/form-data">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h3 class="modal-title">Change Profile Picture</h3>
        </div>

        <div class="modal-body">

        <div class="form-group">
            <label>Upload New Profile Picture</label>
            <input type="file" name="image_file" id="image_file" size = "20" class="form-control"/> 
        </div>

        <input type="hidden" id="picture_id" class="form-control">

    <div class="modal-footer">

        <input type="submit" value="Submit"> 
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>

        </div>
   </form>
添加这些行

$extension = pathinfo($FILES["image_file"]["name"], PATHINFO_EXTENSION); // <<this
$config['upload_path'] = './upload/userimage/';  
$config['allowed_types'] = 'jpg|jpeg|png|gif';  
$config['file_name'] = rand(100,10000).time().".".$extension; //<<and this
$this->load->library('upload', $config);  

$extension=pathinfo($FILES[“image_file”][“name”],pathinfo_extension);//您的代码易受sql注入攻击!使用更好的方法生成随机文件名是
random\u bytes
(连同
bin2hex
),而不是
rand(10010000).time()
,它不是加密RNG。更可靠的方法是检查上传是否成功,以避免覆盖现有文件。另见
$extension = pathinfo($FILES["image_file"]["name"], PATHINFO_EXTENSION); // <<this
$config['upload_path'] = './upload/userimage/';  
$config['allowed_types'] = 'jpg|jpeg|png|gif';  
$config['file_name'] = rand(100,10000).time().".".$extension; //<<and this
$this->load->library('upload', $config);