I'm having difficulties changing the file name of a generated word document. Basically, someone fills out a form from gravity form, and a plugin (that I bought) converts it into a wordfile, the file name is document_ ($entry[ 'id' ] . '-' . $feed[ 'id')

Basically, what I want to do is generate the file name from a merge tag like "first name"

Below is some of the code that will hopefully shed some light. The entire class file is about 700 lines, not sure if I should post the whole file.

            /* check if there is a document to attach */

            $filename = trailingslashit( $uploadDir[ 'path' ] ) . 'documents/document_' . sha1( $entry[ 'id' ] . '-' . $feed[ 'id' ] ) . '.docx';               

            if( is_file( $filename ) )
            {

                $mergeDocumentNames .= '<br />' . $uploadDir[ 'path' ] . '/documents/document_' . sha1( $entry[ 'id' ] . '-' . $feed[ 'id' ] ) . '.docx';
                $mergeDocumentLinks .= '<a href="' . $uploadDir[ 'url' ] . '/documents/document_' . sha1( $entry[ 'id' ] . '-' . $feed[ 'id' ] ) . '.docx' . '" target="_blank" >Document_' . sha1( $entry[ 'id' ] . '-' . $feed[ 'id' ] ) . '.docx</a>';


            }


        }


        /* replace the merge tag with the created filenames */

        if( $mergeDocumentNames )
            $text = str_replace( '{gfdocs:documentnames}', $mergeDocumentNames, $text );

        /* replace the merge tag with the created image links */

        if( $mergeDocumentLinks )
            $text = str_replace( '{gfdocs:documentlinks}', $mergeDocumentLinks, $text );


        return( $text );


    }

This is the code that saves the file

closed as off-topic by Krzysiek Dróżdż, shanebp, Jacob Peattie, bosco, rudtek Dec 11 at 19:10

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.