Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Store an uploaded Image into database using Coco File Uploader
- ==============================================================
- a sample class file ready to be used with Coco Extension (Ajax File Uploader)
- https://github.com/christiansalazar/coco
- */
- class MyModel {
- public function onFileUploadedPromoImage($fullName, $userData){
- // STEP 1:
- // determine the Mime Type, you must store it in your database
- // for future usage
- list($w, $h, $xmime) = getimagesize($fullName);
- $mime = '';
- if($xmime == 2)
- $mime = 'image/jpg';
- if($xmime == 3)
- $mime = 'image/png';
- // STEP 2:
- // store the uploaded file into a "LONG BLOB" in your database
- //
- $img = new Image();
- $img->mimetype = $mime;
- $img->alt = '';
- $img->original_width = $w;
- $img->original_height = $h;
- $img->image_size = filesize($fullName);
- $img->picture_position = 0;
- // Read the image data into the LONG_BLOB field
- $f = fopen($fullName,"r");
- $img->image = fread($f,$img->image_size);
- fclose($f);
- if($img->save()){
- // ok is stored
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement