giving an uploading file name the value of a field
-
Hi,
SCENARIO:
I’ve added a field “upload_your_file”. It’s a “file upload field” type.
I have also 2 new fields:
birthday (date field)
lastname (text-line field)Let’s say a user is in the Frontend Record Edit Form, and is uploading a file in the “upload_your_file” field. i.e. myfile.txt
OBJECTIVE:
I’d like the plugin to save that file with a custom filename:
filename= lastname-birthday.extwhere “ext” is the original extension (in my example, “txt”)
I see there is the function “_handle_file_upload” in participants-database.php and I guess I should edit something there but I am not a programmer.
I just can imagine that the part of the code should be// validate and construct the new filename using only the allowed file extension $new_filename = preg_replace(array('#\.#', "/\s+/", "/[^-\.\w]+/"), array("-", "_", ""), $matches[1]) . '.' . $matches[2]; // now make sure the name is unique by adding an index if needed $index = 1; while (file_exists(xnau_Image_Handler::concatenate_directory_path(ABSPATH, self::$plugin_options['image_upload_location']) . $new_filename)) { $filename_parts = pathinfo($new_filename); $new_filename = preg_replace(array('#_[0-9]+$#'), array(''), $filename_parts['filename']) . '_' . $index . '.' . $filename_parts['extension']; $index++;
Could you please give me a hand?
Thank you.
- The topic ‘giving an uploading file name the value of a field’ is closed to new replies.