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.
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.
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.
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 ?
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.
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.