Using CodeIgniter, I am trying to modify the name of the uploaded file to camelCase by removing any spaces and capitalizing subsequent words.
I am pretty sure that I can rename the file using the second parameter of move_uploaded_file but I don't even know where to look to figure out how to modify the name to camelCase.
Thanks in advance! Jon
Check out CI's upload library:
http://www.codeigniter.com/user_guide/libraries/file_uploading.html
Let's first take a look at how to do a simple file upload without changing the filename:
It's that simple and it works quite well.
Now, let's take a look at the meat of your problem. First we need to get the file name from the $_FILES array:
Then we can split the string with a
_
delimiter like this:Then we'll have to iterate over the list and make a new string where all except the first spot have uppercase letters:
Now that we have the new filename, we can revisit what we did above. Basically, you do everything the same except you add this $config param:
And that should do it! By default, CI has the
overwrite
$config param set toFALSE
, so if there are any conflicts, it will append a number to the end of your filename. For the full list of parameters, see the link at the top of this post.that should work too