slowly I get used to ACF pro, it is truly a swiss army knife, even for “pseudo-programmers” like me.
I could, howewer, need some help with the following: I have a CPT named lyrics. I now have a fieldset for that, containing some text fields like composer, title, etc. and a repeater that has a file upload and a few more text fields in it, I would like to use this for an audio player.
What I want to achieve now is the following:
a) Restrict the file upload to mp3 files only, and
b) get my hands on the uploaded file to manipulate it in several ways (rename it, cut out a preview file from it – no worries about this part, I have a working class for this task – and finally move it to a special folder outside my root)
I realized such thing years ago for another CMS that I was using in my pre WordPress days, now I try to recreate and enhance this for my newest WP-Project.
Does anybody have a hint for me? Any help is gladly appreciated.
Greetings from Germany!
Hi @sixtyseven from Germany 🙂
I’ll respond in the same manner as the questions asked:
a) In the settings for the file field you’ll find “Allowed file types”. Enter mp3 there and you should be good to go!
b) You can get the file wherever you want using get_field(‘filename’). But since your file field is in a repeater you could do:
<?php $repeater = get_field('repeaterfield'); if( $repeater ): foreach( $repeater as $row ): //$file contains either a file array, url or ID depending on what you've set in the field settings. $file = $row['filefield']; //Now you're free to play around with $file :) endforeach; endif; ?>
first of all thank you for taking the time to answer my question. But I think, I did not explain myself well enough. The problem is not to get the file somewhere in the theme, after its saved, repeater or not. I need to hook into the moment when the file was uploaded, but BEFORE the data of the field set is stored into the database.
In other words: I create a post, populate the acf fields and click the save post button. That’s where the mumbo jumbo should happen: Create and store a preview file, move the uploaded file to another location, where it is not accessible by the public, give the file path of the newly created preview mp3 as the new value to the former file upload field and finally save the post and all it’s meta data.
Does that makes it somewhat clearer? Is there any hook, that I could make use of?
The topic ‘handle file uploads’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!