uploading multiple files to different folders |
[eluser]A.M.F[/eluser]
hello guys, i am working on file uploading for my control panel. i have set a multipe file uploading that looks like that- Code: $config['upload_path'] = './uploads/'; but in here, all the files goes to the same path: uploads. how can i config a different upload_path for each file before calling the library? i can't do it with an if statment, cuz i am uploading the files from the same form. what can i do?
[eluser]xwero[/eluser]
Code: $this->load->library('upload'); // no config values
[eluser]xwero[/eluser]
as an alternative for if else structure you could do Code: $config['upload_path'] = ($field == 'somefield')?'./uploads2/':'./uploads/';
[eluser]A.M.F[/eluser]
thanks. xwero - can u explain a little bit aboutthis structure? i always see it but i don't understnd it
[eluser]xwero[/eluser]
It's called Ternary Operator. In short it's a compressed if else structure where you have the condition is followed by a question mark with the values behind the question mark separated by a colon. The biggest benefit is that you don't have to rewrite the variable where you assign the values too. I always use following structure; $variable = condition ? true value : false value;
[eluser]A.M.F[/eluser]
i see. thank u! ---- i have another problam. i want to replace the file name when i am uploading it. i know how to change it through the Upload library, but tht involving editing the code. i wonder if there is any other way to do it?
[eluser]xwero[/eluser]
You could do the renaming while looping through the uploads array. |
Welcome Guest, Not a member yet? Register Sign In |