I'm creating a media upload section in my metabox. One of the things I want to be able to do is to rename the filename of the media that is uploaded to the same as the post title. so for example, say now I uploaded a picture called, pic001.jpg to the post: "Test Post", in the process of the upload, I want to automatically rename the filename to test\_post\_1.jpg

I've seen the following link:

[Rename files during upload using variables](https://wordpress.stackexchange.com/questions/5505/rename-files-during-upload-using-variables)

However, I'm not too sure where you would post the data to? I've also found another link that demonstrates how you can rename the file - it's something similar to this: 

```
function make_new_filename($filename){
$info = pathinfo($filename);
    $ext  = empty($info['extension']) ? '' : '.' . $info['extension'];
    $name = basename($filename, $ext);
    $newname = "test";
    return $newname . $ext;
}
add_filter('sanitize_file_name', 'make_new_filename');

```

So if there any idea how I would get the title posted through to the media\_upload.php?

Follow up: 

I have tried to send the data to the media\_upload.php

```
jQuery('#upload_image_button_test').click(function() {
        var postTitleVal = jQuery("#title").val();
        if(postTitleVal == ''){
            jQuery("#title").after('<span class="error"> You forgot to enter the title</span>');
        } else{
        jQuery('html').addClass('Image');
        formfield = jQuery('#upload_image_test').attr('name');
        tb_show('', 'media-upload.php?type=image&TB_iframe=true;title='+postTitleVal);
        console.log('media-upload.php?type=image&TB_iframe=true;title='+postTitleVal);
        }

        return false;
    });

    // user inserts file into post. only run custom if user started process using the above process
    // window.send_to_editor(html) is how wp would normally handle the received data

    window.original_send_to_editor = window.send_to_editor;
    window.send_to_editor = function(html){

        if (formfield) {
            fileurl = jQuery('img',html).attr('src');

            jQuery('#upload_image_test').val(fileurl);

            tb_remove();

            jQuery('html').removeClass('Image');

        } else {
            window.original_send_to_editor(html);
        }
    };

});

```