PHP:save file on mysql

Now that I think of it, you should encode the file contents using something like base64:

$the_file_contents = base64_encode(file_get_contents('path/to/file'));
$query = "insert into (the_column_name) values ('$the_file_contents')";
// Execute the query

// When reading the values:
$file_contents = base64_decode($encoded_file_contents);
// $encoded_file_contents is the data from the database
1 Like