General developer forum

File API - how do you *move* a file?

This discussion has been locked because a year has elapsed since the last post. Please start a new discussion topic.
Picture of Howard Miller
Re: File API - how do you *move* a file?
Group Core developersGroup Documentation writersGroup Particularly helpful MoodlersGroup Plugin developers

Thanks! I actually got there just before you posted. What was tripping me up was that 'create_file_from_storedfile() fails if the destination file already exists. This sounds obvious now but wasn't what I expected and one tends to run the same thing multiple times during testing. 

So... to be on the safe side, an $fs->get_file(...) with the same details as $dest (unfortunately it won't accept the same array -booh) followed by a delete if it succeeds. 

Average of ratings: -