0

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.

4

1 回答 1

1

你没有很清楚地说明你的问题:

名称是否根本没有被加密,但仍然上传到正确的目录?

您是否将这些设置在一个循环中,而类实例可能没有被重新初始化?第一个文件是否正确加密,但后续文件不正确?

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

我很难相信它完全是“随机的”,并且认为这里没有足够的研究


下面的解决方案:

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

于 2013-05-05T01:05:12.237 回答