The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
cant get rename file on upload to work
Hi,
im trying to rename files that are uploaded by a form.The filename should contain the value of two fields separated by "-".
This is my code:
function rename_file($filename, $filename_raw) {
if ($_POST['form_id'] == '3') {
$id = $_POST['item_meta[11]'] . '-';
$name = $_POST['item_meta[12]'];
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$new = "test" . $id . $name . $ext;
if( $new != $filename_raw ) {
$new = sanitize_file_name( $new );
}
return $new;
} else {
return $filename;
}
}
add_filter('sanitize_file_name', 'rename_file', 10, 2);
When uploading a file the name is changed to Example:"-.mp4".
I can't find the issue. According to other forum posts the code should work
March 12, 2018 at 10:58 am
EDIT:
<?php
function rename_file($filename, $filename_raw) {
if ($_POST['form_id'] == '3') {
$id = $_POST['item_meta'][11] . '-';
$name = $_POST['item_meta'][12];
$info = pathinfo($filename);
$ext = empty($info['extension']) ? '' : '.' . $info['extension'];
$new = "test" . $id . $name . $ext;
if( $new != $filename_raw ) {
$new = sanitize_file_name( $new );
}
return $new;
} else {
return $filename;
}
}
add_filter('sanitize_file_name', 'rename_file', 10, 2);
March 12, 2018 at 12:07 pm
I have seen: as of the release of Formidable Pro V2.02, the process will no longer work.
Discussion closed.