Codeigniter多文件上传加密问题 [英] Codeigniter Multiple File Upload Encryption Issue

查看:167
本文介绍了Codeigniter多文件上传加密问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的表单,允许用户上传多个文件/文件类型到他们正在创建的报价/出价。一切工作正常,除了一块:保存到数据库之前的文件的名称加密。



我没有找到一个韵律或理由,但它的命中或错过。图像每次都很好。其他文件(允许所有[*]类型,但主要将包括各种业务文档,如pdf,doc,xls等)是那些是斑驳的。

我在SO和其他地方发现了关于名称加密的一般问题的线程,但是还没有碰到一个涉及我的问题的特殊性的线程。



这里是上传功能:

  //用于多次上传
函数do_uploads($ name,$ file)
{
$ status =;
$ msg =;
$ file_element_name = $ name;


//找出它的位置
if($ name ==QuoteDoc){
$ folder =quotedocs;
$ allowed ='*';
}
else if($ name ==ProductOfferPhoto){
$ folder =product_photos;
$ allowed ='jpeg | jpg | png | gif';
}
else if($ name ==ResearchWhtPaper1|| $ name ==ResearchWhtPaper2){
$ folder =research;
$ allowed =*;
}
else if($ name ==ProductLiterature1|| $ name ==ProductLiterature2){
$ folder =literature;
$ allowed =*;
}
else if($ name ==FDALink){
$ folder =fda;
$ allowed =*;
}


$ config ['upload_path'] ='./uploads/'。 $文件夹;
$ config ['allowed_types'] = $允许;
$ config ['max_size'] = 1024 * 8;
$ config ['encrypt_name'] = TRUE;

$ this-> load->库('upload',$ config);
$ b $ if(!$ this-> upload-> do_upload($ name))
{
$ status ='error';
$ msg = $ this-> upload-> display_errors('','');

else {
$ data = $ this-> upload-> data();
}

@unlink($ _ FILES [$ file_element_name]);

//怎么了?
// return $ this-> upload-> data();
return array('status'=> $ status,'msg'=> $ msg,'data'=> $ this-> upload-> data(),'allowed'=> $允许的);

code $


任何帮助都将不胜感激。
<解决方案

这个名字没有被加密,仍然上传到正确的目录?

你是在一个循环内部设置这些内容吗,那里的类实例没有被重新初始化?第一个文件加密是否正确,但不是后面的文件加密?



您可以跟踪哪些文件类型无法正常工作吗?

我很难相信它是完全随机的,并认为这里没有足够的研究正在进行中。




下面的解决方案:

您需要使用$ this-> upload-> initialize($ config)来更改配置,因为库只会被加载一次


I've got a big form that allows users to upload multiple files/filetypes to an offer/bid they are creating. Everything is working fine except one piece: the name encryption of the files before saving to the database.

I haven't found a rhyme or reason for it, but it's hit or miss. The image works fine every time. The other documents (which allow all [*] types, but primarily will consist of various business docs such as pdf, doc, xls, etc.) are the ones that are spotty.

I found threads on SO and elsewhere about general issues with the name encryption but have yet to come across one that deals with the specificity of my issue.

Here's the upload function:

//for multi uploads
        function do_uploads($name, $file)
        {
            $status ="";
            $msg = "";
            $file_element_name = $name;


            //go through and figure out where it goes
            if($name == "QuoteDoc") {
                $folder = "quotedocs";
                $allowed = '*';
            }
            else if($name == "ProductOfferPhoto") {
                $folder = "product_photos";
                $allowed = 'jpeg|jpg|png|gif';
            }
            else if($name == "ResearchWhtPaper1" || $name == "ResearchWhtPaper2") {
                $folder = "research";
                $allowed = "*";
            }
            else if($name == "ProductLiterature1" || $name == "ProductLiterature2") {
                $folder = "literature";
                $allowed = "*";
            }
            else if ($name == "FDALink") {
                $folder = "fda";
                $allowed = "*";
            }


            $config['upload_path'] = './uploads/' . $folder;
            $config['allowed_types'] = $allowed;
            $config['max_size']  = 1024 * 8;
            $config['encrypt_name'] = TRUE;

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

            if ( ! $this->upload->do_upload($name))
            {
                $status = 'error';
                $msg = $this->upload->display_errors('', '');
            }
            else {
                $data = $this->upload->data();
            }

            @unlink($_FILES[$file_element_name]);

            //what's up?
            //return $this->upload->data();
            return array('status' => $status, 'msg' => $msg, 'data' => $this->upload->data(), 'allowed'=>$allowed);
        }

Any help would be greatly appreciated.

解决方案

You're not stating your question very clearly:

Are the names simply not being encrypted, but still uploading to the correct directories?

Are you setting these inside a loop, where perhaps the class instance is not being re-initialized? Does the first file encrypt correctly, but not the subsequent ones?

Can you track which file types are not working correctly?

I have trouble believing it is completely "random", and think there's just not enough research being done here


Solution from below:

You need to use $this->upload->initialize($config) to change the config, as the library will only be loaded once

这篇关于Codeigniter多文件上传加密问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆