Support Forum
Support › MB Custom Table › Choose File in custom tableResolved
Dear Anh,
How would I store a "Choose File" in a custom table?
Thank you
Dave
Or how to store the file path in the custom table?
Hi Dave,
All media fields store attachment IDs by default. If you want to store file URL (not path), then you can try file
field with upload_dir
settings. See this for details:
https://docs.metabox.io/fields/file/#upload-to-custom-folder
Dear 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
Dave
Hi 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.
Dear 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' ) );
}
Also my array for the image is as follows.
array (
'id' => 'image_26',
'type' => 'image',
'name' => 'Business Logo',
'max_file_uploads' => 2,
Probably 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 be a:2:{i:0;i:12;i:1;i:34;}
. It's longer than what we think 🙂
Dear 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.
I don't see anything wrong here. Do you see other fields saved in the database?
Dear 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.
If 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?
Dear Anh,
I have checked the usermeta and its not saving the image_26 in there.
Yes all the fields are in one meta box.
Dear Anh,
Did you find anything wrong with my code that might cause this problem?
Thank you
Dave
Dear Anh,
Where you able to see if there was a problem with me code?
Thank you
Dave