Saturday 15 March 2014

mysql - PHP handle a blob without creating a file -



mysql - PHP handle a blob without creating a file -

i there way handle blob(a file saved mysql) without having create file?

i need retrive blob db, wich can kind of file, img, text, video, etc. , able show in html.

so far, managed create file , work it. has little problem , have delete after user stop working file. can not create cronjob(or simillar) delete these files after time.

any ideas?

thanks!

you can have script prints content of file on-the-fly database. have store content-type , retrive content database.

#showfile.php $contenttype = ... // retrive content type database $blob = ... // retrive blob database header('content-type: ' . $contenttype); echo $blob;

if don't have mime type saved in database, can seek this: determinate mime type mysql column

function mimetype($data) { //file signatures associated mime type $types = array( "474946383761"=>"image/gif", //gif87a type gif "474946383961"=>"image/gif", //gif89a type gif "89504e470d0a1a0a"=>"image/png", "ffd8ffe0"=>"image/jpeg", //jfif jpeg "ffd8ffe1"=>"image/jpeg", //exif jpeg "ffd8ffe8"=>"image/jpeg", //spiff jpeg "25504446"=>"application/pdf", "377abcaf271c"=>"application/zip", //7-zip zip file "504b0304"=>"application/zip", //pk zip file ( match other file types docx, jar, etc ) ); $signature = substr($data,0,60); //get first 60 bytes shouldnt need more determine signature $signature = array_shift(unpack("h*",$signature)); //string representation of hex values foreach($types $magicnumber => $mime) { if( stripos($signature,$magicnumber) === 0 ) homecoming $mime; } //return octet-stream (binary content type) if no signature found homecoming "application/octet-stream"; }

php mysql

No comments:

Post a Comment