Support

Account

Home Forums ACF PRO Own custom field type to upload files

Solved

Own custom field type to upload files

  • Hello,

    i need an acf-field-type, which uploads files to the server in a special folder, but without create a attachment post.

    i used the kit from this site.

    in functions.php i added a filter to change the form enctype

    add_action('post_edit_form_tag', 'post_edit_form_tag');
    
    function post_edit_form_tag() {
      echo ' enctype="multipart/form-data"';
    }

    So $_FILES would be filled on save or update.

    I create in my acf-field-type a filter for wp_handle_upload_prefilter and it works in this way, that die file will be uploaded and moved in the right folder.

    But after this the file will save in media library. And this should happens. The returned value should be the file-name.

    I don’t find the place where acf_upload_files(); from media.php will be called.

    can anyone help me???

    So long
    Skrabbel

  • Hi @skrabbel

    I’m not sure I understand your question. Could you please explain it in more details?

    If you only need to upload the file, I believe you can use the wp_handle_upload() function.

    Thanks πŸ™‚

  • Hello @acf-support,

    sorry my english is terrible.

    I want to upload a file. But i don’t want an insert in the media library.

    My problem isn’t the upload. The file is at the right place and so on.

    My problem is the automatic in acf to create after upload this attachment insert in the database.

    I use a filter for wp_handle_upload_prefilter – but after this it starts ever the function acf_upload_files();. I look for a way to prevent or to stop this. Because this function create the media library insert. I don’t want this insert.

    I will upload advertising images. These images has only one size! And i don’t need the other formats.

    I can upload, but i can’t the insert in the database and the media libary.

    Thanks vor your help!

    Greetings
    Skrabbel

  • Hi @skrabbel

    Maybe you can copy the files to the new location, get the URL to the new location and then delete the attachment by using the wp_delete_attachment() function?

    It’s a little bit hacky, I guess. But I think this is the easiest way to do it.

    Thanks πŸ™‚

  • Hi @acf-support

    this is the plan, if nothingelse will work.

    I create “only” many IDs.

    And with a filter for “save_post” i rewrite the value for the custom field. Otherwise it used the id of the attachment. Right?

  • Hi @skrabbel

    I’m afraid I don’t understand your question, so please forgive me if I’m wrong.

    If you use a file field type and acf/save_post to modify the value to something else other than ID, ACF won’t recognize it as a file and the backend will show the field as empty.

    If you need to upload the files but don’t want it to show up in the media library, maybe you can upload it manually by using a PHP code? This page should give you more idea about it: http://www.w3schools.com/php/php_file_upload.asp, http://php.net/manual/en/features.file-upload.php.

    I hope this makes sense πŸ™‚

  • Hello @acf-support,

    This function is still alive and works fine.

    You wrote:

    “Maybe you can copy the files to the new location, get the URL to the new location and then delete the attachment by using the wp_delete_attachment() function?”

    “Maybe you can copy the files to the new location”

    -> this works fine.

    “get the URL to the new location”

    -> I have the url.

    “and then delete the attachment by using the wp_delete_attachment() function”

    -> I wanted to do so when nothing works. I create so but a lot IDs in wp_posts. I was looking for a better solution.

    I wanted to do this with a filter for β€œsave_post”. I delete first the attachment from the media library and then i overwrite the attachment_id with the url of to the new location. Right?

    excuse my bad English.

    Greetings
    Skrabbel

  • Hi @skrabbel

    If you overwrite the attachment_id with the URL in a file field type, it won’t show anything on the backend because the file field type can only read attachment ID from the database, not the URL. If you want to do it, I suggest you add a new URL field type and save the image URL in that field instead.

    I hope this makes sense πŸ™‚

  • Used a plugin. Pictures from Users are no longer in the Media Libary.

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Own custom field type to upload files’ is closed to new replies.