Wednesday, 15 January 2014

php - Codeigniter set double config upload -


I am trying to create multiple configurations for the upload file. This is my code:

  $ config ['upload_path'] = './upload/post'; $ Config ['allowed_types'] =' jpg | PNG | GIF | JPEG | JPG | PNG | GIF | JPEG '; $ Config ['overwrite'] = true; $ This- & gt; Load-> Library ('upload', $ config); $ Files = $ _FILES; $ File = $ _ files ['userfile'] ['name']; $ File_array = array (); ($ I = 0; $ i & lt; 1; $ i ++) {$ temp = Explosion (".", $ Files ["userfile"] ["name"] [$ i]); $ Newfilename = mt_rand () '.' .end ($ temp); $ _FILES ['userfile'] ['name'] = $ newfilename; $ _FILES ['userfile'] ['type'] = $ files ['userfile'] ['type'] [$ i]; $ _FILES ['userfile'] ['tmp_name'] = $ files ['userfile'] ['tmp_name'] [$ i]; $ _FILES ['userfile'] ['Error'] = $ files ['userfile'] ['error'] [$ i]; $ _FILES ['userfile'] ['size'] = $ files ['userfile'] ['size'] [$ i]; $ File_array [$ i] = $ _ files ['userfile'] ['name']; $ This- & gt; Upload-> Start ($ config); $ This- & gt; Upload-> Do_upload (); $ This- & gt; Upload-> Data (); } / * Second upload file * / $ config2 ['upload_path'] = './upload/file'; $ Config2 ['permission_type'] = 'jpg | Png | Gif | Jpeg | Jpg | Png | Gif | Jpeg ';; $ This- & gt; Load-> Library ('upload', $ config2); $ File_data = $ _FILES; $ Data_file = $ _ files ['file_data'] ['name']; $ Data_array = array (); ($ X = 0; $ x & lt; 1; $ x ++) {$ ex = Explosion (".", $ File_data ["file_data"] ["name"] [$ x]); $ Filename = mt_rand () '.' .end ($ east); $ _FILES ['file_data'] ['name'] = $ filename; $ _FILES ['file_data'] ['type'] = $ file_data ['file_data'] ['type'] [$ x]; $ _FILES ['file_data'] ['tmp_name'] = $ file_data ['file_data'] ['tmp_name'] [$ x]; $ _FILES ['file_data'] ['Error'] = $ file_data ['file_data'] ['Error'] [$ x]; $ _FILES ['file_data'] ['size'] = $ file_data ['file_data'] ['size'] [$ x]; $ Data_array [$ x] = $ _ files ['file_data'] ['name']; $ This- & gt; Upload-> Start ($ config2); $ This- & gt; Upload-> Do_upload (); $ This- & gt; Upload-> Data (); } / * End upload file script * /  

How do I set up several configs? Is this possible?

Do you have any other way to upload more than one file with different name file tags?

You are currently overwriting the same configuration, you need to create an array of upload configuration . Like this:

  $ config ['upload_configs'] = array (); $ Config ['upload_configs'] [0] ['upload_path'] = './upload/post'; $ Config ['upload_configs'] [1] ['upload_path'] = './upload/file'; ....  

No comments:

Post a Comment