Files and Folders

Official documentation on the file system: https://docs.joomla.org/How_to_use_the_filesystem_package

Also see the jInput file array structure.

Example usage

public function catchJFormFile($file)
{
    $this->original_filename = JFile::makeSafe($file['name']);
    $this->tmp_src = $file['tmp_name'];
    $this->original_filesize = $file['size'];
    $this->original_filetype = JFile::getExt($this->original_filename);
    $this->storage_path = JPATH_COMPONENT . '/documents/' . $this->id;
    $this->temp_storage_path = $this->storage_path . '/temp';
    $this->setupFolder();
    $this->original_file_dest = $this->storage_path . '/original.' . $this->original_filetype;
    JFile::upload($this->tmp_src, $this->original_file_dest);
}

private function setupFolders()
{
    // doesn't matter if folders exist or not
    JFolder::create($this->storage_path);
    JFolder::create($this->storage_path . '/temp');
}

private function deleteTempFiles()
{
    $existing_temp_files = JFolder::files($this->storage_path . '/temp');
    foreach($existing_temp_files as $file_to_delete){
        JFile::delete($this->storage_path . '/temp/' . $file_to_delete);
    }
}