How to retrieve/download a file stored in a BLOB in a MySQL DB using PHP -


the other day wrote program takes file user provided , inserts actual file(driver) mysql database blob. did insertion follows:

$sql = "insert drivers (driver, filename, status, version, environments) values(load_file('$driver'), '$filename', $statusid, $driver_version, '$environments')"; 

as can see above, 'driver' field blob. have filename in different field. question is, how can blob , put actual file? need file can upload server via scp. i've seen few examples out there content headers , such , complicated. easy load load_file() , didn't know if there simple option actual file? sorry don't have code examples. don't know start.

your sql table should have @ least 2 fields:

`mime_type` varchar(255) not null, `size` int(10) unsigned not null, 

where:

  • mime_type mime_content_type($path) and
  • size file's size in bytes, filesize($path)

and php code should like:

header("pragma: public"); header("expires: 0"); header("cache-control: must-revalidate, post-check=0, pre-check=0"); header("content-type: {$file['mime_type']}"); header("content-transfer-encoding: binary"); header("content-length: {$file['size']}"); header("content-disposition: inline; filename= {$file['filename']}");  return $file['driver']; 

the reasons storing data binary in sql dictated business rules. example, store contracts have remain private.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -