Title: Set attachment folder via php
Last modified: February 1, 2022

---

# Set attachment folder via php

 *  Resolved [jakobmetro](https://wordpress.org/support/users/jakobmetro/)
 * (@jakobmetro)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/set-attachment-folder-via-php/)
 * Is there a simple php function I can call within my theme’s function.php that
   can add my given attachment id, and then set the folder for the attachment? I’m
   trying to set up an upload process via a form that the user submits, which I’ve
   hooked up to take that image form field and save it as an attachment post in 
   the wp media gallery. The only step I have left is to set the folder of that 
   attachment. Is there a simple php function I can call that can do that?
 * I see in your documentation, there is a [json api](https://ninjateam.gitbook.io/filebird/api),
   but that seems overkill to open a connection, set up a bearer token, etc. to 
   the site’s own json api just to set a row in a table… I’m already within the 
   site, the json api only seems useful if I’m trying to do that outside of my current
   wp instance (for some reason). Just want to see if there’s a better way, or if
   I’m missing something.

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

 *  Plugin Support [Bruce](https://wordpress.org/support/users/ninjateamwp/)
 * (@ninjateamwp)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/set-attachment-folder-via-php/#post-15322046)
 * Hi [@jakobmetro](https://wordpress.org/support/users/jakobmetro/) ,
 * Thanks for writing to us!
    Please allow me to check this with our developers 
   and give you their opinion later.
 * Kind regards,
    -Bruce-
 *  Plugin Support [Bruce](https://wordpress.org/support/users/ninjateamwp/)
 * (@ninjateamwp)
 * [4 years, 4 months ago](https://wordpress.org/support/topic/set-attachment-folder-via-php/#post-15327517)
 * Hi [@jakobmetro](https://wordpress.org/support/users/jakobmetro/) ,
 * The recommendation are these references:
 * [https://wordpress.org/support/topic/set-image-folder-using-php/](https://wordpress.org/support/topic/set-image-folder-using-php/)
   
   [https://wordpress.org/support/topic/place-new-images-into-folder/](https://wordpress.org/support/topic/place-new-images-into-folder/)
 * Please try any of them.
 * Kind regards,
    -Bruce-

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

The topic ‘Set attachment folder via php’ is closed to new replies.

 * ![](https://ps.w.org/filebird/assets/icon-128x128.gif?rev=2299145)
 * [FileBird - WordPress Media Library Folders & File Manager](https://wordpress.org/plugins/filebird/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/filebird/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/filebird/)
 * [Active Topics](https://wordpress.org/support/plugin/filebird/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/filebird/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/filebird/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Bruce](https://wordpress.org/support/users/ninjateamwp/)
 * Last activity: [4 years, 4 months ago](https://wordpress.org/support/topic/set-attachment-folder-via-php/#post-15327517)
 * Status: resolved