Choose File in custom table
Support › MB Custom Table › Choose File in custom tableResolved
- This topic has 23 replies, 2 voices, and was last updated 5 years, 10 months ago by
tsttech.
-
AuthorPosts
-
May 28, 2019 at 10:39 PM #14737
tsttech
ParticipantDear Anh,
How would I store a "Choose File" in a custom table?
Thank you
DaveMay 28, 2019 at 10:51 PM #14738tsttech
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.
May 29, 2019 at 2:51 PM #14761Anh Tran
KeymasterIf the field is updating, that means it still saves values in the post meta. Can you verify that?
And did you put all the fields in one meta box?
May 29, 2019 at 2:57 PM #14762tsttech
ParticipantDear Anh,
I have checked the usermeta and its not saving the image_26 in there.
Yes all the fields are in one meta box.
May 31, 2019 at 12:46 PM #14792tsttech
ParticipantDear Anh,
Did you find anything wrong with my code that might cause this problem?
Thank you
DaveJune 3, 2019 at 2:51 PM #14810tsttech
ParticipantDear Anh,
Where you able to see if there was a problem with me code?
Thank you
Dave -
AuthorPosts
- You must be logged in to reply to this topic.