I check the below answer to rename files during upload and tries to change it to something like postid_originalfilename.jpg but failed. Any help?
function make_filename_hash($filename) {
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$name = basename($filename, $ext);
return md5($name) . $ext;
}
add_filter('sanitize_file_name', 'make_filename_hash', 10);
https://stackoverflow.com/questions/11586284/rename-files-on-upload-in-wordpress-3-4-1
If you want to use the above
sanitize_file_name
filter, you could try this:where for example
image.jpg
is changed to123_image.jpg
where 123 is the parent post id.