Forums

Store Image to a blob field in database

prashanth.sp.rao956 30 Jul, 2024

HI,

I have a small contact form with the following fields

  1. First Name
  2. Last Name
  3. Email
  4. Mobile Number
  5. Photo

I am looking to store the image of this contact in the blob field of the database table. But it is not working.

Can you please guide?

Thanks !

Max_admin 09 Aug, 2024
Answer

You need to read the image file saved by the upload action then store the file data into a variable, you can do these 2 steps in 1 PHP action:

$file_path = $this->get("upload_action_name.path"); // you get this from the form debug, it will show you the file path 
$file_data = file_get_contents($file_path, true);
return base64_encode($file_data);

then use {var:php_action_name} in your Save Data fields

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.