PHP Codeigniter上传类,重命名具有特定架构的文件

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了PHP Codeigniter上传类,重命名具有特定架构的文件脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我在使用CodeignITer时遇到了麻烦,并且在上传过程中从要提供的上传库中重命名文件.现在在任何人说出来之前,我并不是在寻找“加密”的文件名.

我的问题是在上传图片时,你可以处理好一些类型.那么如何使用file_name配置选项将文件名更改为特定模式(我已经将模式部分启动并运行).但保持相同的文件类型?

现在我正在尝试

$upload_config [‘file_name’] = $generated_filename_From_schema

唯一的问题是$generated_filename_from_schema没有文件扩展名,并且将文件扩展名保留在等式CI之外似乎完全忽略它并且只是获取文件并且apPEnd_1,_2,_3如果文件具有相同的名称则上升,否则它只是保留了名称.

现在我必须将$config传递给CI,以便上传文件,但是如何在上传之前确定我正在使用哪种文件,这样我就可以使用我的名字生成模式.

*编辑*

$upload_config['upload_path'] = realpath(APPPATH.'../images/');
    $upload_config['Allowed_types'] = 'gif|jpg|png';
    $upload_config['max_size']  = 0;
    $upload_config['max_width'] = 0;
    $upload_config['max_height'] = 0;
    $upload_config['remove_spaces'] = true;

    $upload_config['file_name'] = $this->genfunc->genFileName($uid);

    if($this->input->post('uploads'))
    {

        $this->load->library('upload');
        $this->upload->initialize($upload_config);

        if (!$this->upload->do_upload())
        {
            //echo 'error';
            echo $config['upload_path'];
            $this->data['errors'] = $this->upload->display_errors();
        }
        else
        {
            //echo 'uploaded';
            $this->data['upload_data'] = $this->upload->data();
        }
    }

解决方法

您可以使用$_FILES数组来获取文件的原始名称.

解压缩原始文件的扩展名.然后,附加到新文件名.

请尝试以下方式

$ext = end(explode(".",$_FILES[$input_file_field_name]['name']));
$upload_config['file_name'] = $this->genfunc->genFileName($uid).'.'.$ext;

脚本宝典总结

以上是脚本宝典为你收集整理的PHP Codeigniter上传类,重命名具有特定架构的文件全部内容,希望文章能够帮你解决PHP Codeigniter上传类,重命名具有特定架构的文件所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。