Custom Fields
Re-Envisioned › Support › MB Custom Table › Choose File in custom table
- This topic has 23 replies, 2 voices, and was last updated 1 year, 7 months ago by
tsttech.
-
CreatorTopic
-
May 28, 2019 at 10:39 PM #14737
Dear Anh,
How would I store a “Choose File” in a custom table?
Thank you
Dave -
CreatorTopic
-
AuthorReplies
-
May 28, 2019 at 10:51 PM #14738
tsttech
ParticipantOr how to store the file path in the custom table?
May 29, 2019 at 11:06 AM #14742Anh Tran
KeymasterHi Dave,
All media fields store attachment IDs by default. If you want to store file URL (not path), then you can try
file
field withupload_dir
settings. See this for details:https://docs.metabox.io/fields/file/#upload-to-custom-folder
May 29, 2019 at 1:25 PM #14747tsttech
ParticipantDear Anh,
Which is correct way storing the ID or the path? I just want to store the information in the custom table which is why i am asking. As I don’t know.Thank you
DaveMay 29, 2019 at 1:55 PM #14749Anh Tran
KeymasterHi Dave,
Storing ID seems better in my opinion. You can get full file info later with small piece of code. Storing file path doesn’t have any benefit since it’s the raw path on the server, which is unusable.
May 29, 2019 at 2:02 PM #14752tsttech
ParticipantDear Anh,
Ok, this does help, but now the problem is how does one store the ID.
This is what i have already and all is working except the ‘image_26’ => ‘VARCHAR(20)’,
add_action( 'init', 'prefix_create_table' ); function prefix_create_table() { if ( ! class_exists( 'MB_Custom_Table_API' ) ) { return; } MB_Custom_Table_API::create( 'users_member_application_section', array( 'application_date' => 'DATE NOT NULL', 'company' => 'TEXT', 'company_url' => 'TEXT', 'company_details' => 'TEXT', 'what_is_your_preferred' => 'TEXT', 'other' => 'TEXT', 'membership_level_youre_applying_for' => 'TEXT', 'have_you_photographed_animalspets_before' => 'TEXT', 'do_you_currently_offer_pro_bono' => 'TEXT', 'if_yes_please_describe_the_services' => 'MEDIUMTEXT', 'if_no_tell_us_a_little_more_about_why' => 'MEDIUMTEXT', 'what_are_your_goals_of_membership' => 'MEDIUMTEXT', 'primary_artistic_medium' => 'TEXT', 'if_other_please_describe' => 'MEDIUMTEXT', 'how_did_you_hear_about_hearts_speak' => 'TEXT', 'if_someone_referred_you' => 'TEXT', 'hearts_speak_members_provide_their_services' => 'TEXT', 'if_so_please_provide_a_link' => 'VARCHAR(2083)', 'i_have_read_and_agree_to_this_statement' => 'TEXT', 'i_have_read_and_agree_to_adhere' => 'TEXT', 'expired_members' => 'TEXT', 'url_22_facebook' => 'VARCHAR(2083)', 'url_23_instagram' => 'VARCHAR(2083)', 'url_24_twitter' => 'VARCHAR(2083)', 'url_25_google' => 'VARCHAR(2083)', 'image_26' => 'VARCHAR(20)', 'text_27_ip_address' => 'VARCHAR(50) NOT NULL', 'text_28_personal_facebook_account' => 'VARCHAR(2083)', ), array( 'text_27_ip_address' ) ); }
May 29, 2019 at 2:04 PM #14753tsttech
ParticipantAlso my array for the image is as follows.
array (
‘id’ => ‘image_26’,
‘type’ => ‘image’,
‘name’ => ‘Business Logo’,
‘max_file_uploads’ => 2,May 29, 2019 at 2:14 PM #14754Anh Tran
KeymasterProbably you need to increase the length for the field. The value of image field is an array of IDs, which will be serialized before saving in the database.
For example, if you have 2 images
[12, 34]
, then the value will bea:2:{i:0;i:12;i:1;i:34;}
. It’s longer than what we think 🙂May 29, 2019 at 2:23 PM #14755tsttech
ParticipantDear Anh,
I have increased the ‘image_26’ => ‘VARCHAR(2083)’, but its still not saving the image path or ID in the database.The database is just showing “NULL”
Am i doing something incorrect?
Dave.
May 29, 2019 at 2:37 PM #14758Anh Tran
KeymasterI don’t see anything wrong here. Do you see other fields saved in the database?
May 29, 2019 at 2:44 PM #14760tsttech
ParticipantDear Anh,
Yes other fields save, just the image one is not saving. The image field type is updating, but it doesn’t store any data.
I will choose a file and upload it then save the user profile, but the data is not getting updated in the custom table
Dave.
-
AuthorReplies
- You must be logged in to reply to this topic.