• I created front-end form posting.

    Now I want to add to it a file uploader.

    I want to add images before form was send

    Now am thinking how to create it in right way.

    1. I think to create a some sort of temp folder, upload all images in it, after form submit, receive a POST ID and…. at this point I don’t know what I need to do ? How to move images from temp folder and attach it to post ?… or I am wrong with this way ?
Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator threadi

    (@threadi)

    To assign the image to a post, you need to save it in the media library. You can do this using this function: https://developer.ww.wp.xz.cn/reference/functions/media_handle_upload/ – you don’t need to work with temporary files yourself, WordPress does that for you.

    However, I wonder why you are programming this yourself? There are various form plugins that offer this feature, e.g. WPForms in the smallest commercial version or Ninjaforms, as far as I know. There are also instructions for the plugins.

    Thread Starter wildapache

    (@wildapache)

    Oh, I didn’t know it, now I see, I can create attach with a default zero value. Thanks !

    I programming this by myself because I need a clear and fast code and modify it like I want. Most plugins have much “trash code” or unnecessary functions. (because they make it for commercial purposes etc..)

    My will be simple, full modern browsers compatible, full responsive with, fast and clear code.

    Moderator threadi

    (@threadi)

    Glad I could help 🙂 I also use this feature with some plugins… if that answers your question, feel free to mark the topic as resolved.

    Thread Starter wildapache

    (@wildapache)

    This upload method is good, but we will have a one problem !

    What we will do, if user upload an images and won’t send the form ?

    Moderator threadi

    (@threadi)

    Then you have additional files in your media library that are not being used. You would need to consider whether and how this fits into your project plan. You may also need to adjust the process.

    Thread Starter wildapache

    (@wildapache)

    I think in that case I need to create additional plugin-cleaner.

    In anyway “submit refuses” will be not much, because it can do only registered users.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Upload files before create a NEW POST.’ is closed to new replies.