Re: Keeping session alive when loading images from database
I don't see any real advantage in any of the listed so called advantages. Referential integrity (ACID Consistency) Doesnt matter, the file is there or not in the FS. Ease of backup Also just one command to pack the files with your favorit compression programm. Saving of Inodes A FS does this similar to manage itself, as the article also states. No (dis-)advantage at all, its necessary. Easy categorisation See below storage of meta data No Name collisions UUID Storage of Meta Data (data about data) You store the info about the file in the database, not the file, and get it when it is uploaded. You make the database faster by not storing the files inside of and and just its meta data. Central point of operations APP/files Replication over multiple servers Unnecessary by using the FS on a good RAID driven storage system. You can also mount each directory from another server. I dont see any advantage for the DB here. Neither speed wise nor by an easier backup. On Mar 18, 4:32 pm, Daffy jon.bennet...@gmail.com wrote: Faifas, I'll try your suggestion. Thanks. Burzum, there are many good reasons a developer might save images in the database. See here for more information:http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html#1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
IMHO a best of both worlds approach would be to store the images as blobs and use caching for the images later on to speed up the request handling. But depending on the complexities and overheads involved in devising such a solution, it might be better to simply use the FS if it's a simple app. Peace, Syed. On Thu, Mar 19, 2009 at 3:03 PM, burzum bur...@doomzone.de wrote: I don't see any real advantage in any of the listed so called advantages. Referential integrity (ACID Consistency) Doesnt matter, the file is there or not in the FS. Ease of backup Also just one command to pack the files with your favorit compression programm. Saving of Inodes A FS does this similar to manage itself, as the article also states. No (dis-)advantage at all, its necessary. Easy categorisation See below storage of meta data No Name collisions UUID Storage of Meta Data (data about data) You store the info about the file in the database, not the file, and get it when it is uploaded. You make the database faster by not storing the files inside of and and just its meta data. Central point of operations APP/files Replication over multiple servers Unnecessary by using the FS on a good RAID driven storage system. You can also mount each directory from another server. I dont see any advantage for the DB here. Neither speed wise nor by an easier backup. On Mar 18, 4:32 pm, Daffy jon.bennet...@gmail.com wrote: Faifas, I'll try your suggestion. Thanks. Burzum, there are many good reasons a developer might save images in the database. See here for more information: http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html#1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
I appreciate your response but people have debated the usage of BLOBs for a long time so I don't think we should here. Our development team looked at the possibilities for this project and decided on BLOBs. Most of the time we have used the file system. Thanks for your suggestions. On Mar 19, 5:33 am, burzum bur...@doomzone.de wrote: I don't see any real advantage in any of the listed so called advantages. Referential integrity (ACID Consistency) Doesnt matter, the file is there or not in the FS. Ease of backup Also just one command to pack the files with your favorit compression programm. Saving of Inodes A FS does this similar to manage itself, as the article also states. No (dis-)advantage at all, its necessary. Easy categorisation See below storage of meta data No Name collisions UUID Storage of Meta Data (data about data) You store the info about the file in the database, not the file, and get it when it is uploaded. You make the database faster by not storing the files inside of and and just its meta data. Central point of operations APP/files Replication over multiple servers Unnecessary by using the FS on a good RAID driven storage system. You can also mount each directory from another server. I dont see any advantage for the DB here. Neither speed wise nor by an easier backup. On Mar 18, 4:32 pm, Daffy jon.bennet...@gmail.com wrote: Faifas, I'll try your suggestion. Thanks. Burzum, there are many good reasons a developer might save images in the database. See here for more information:http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html#1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
Uhh... why do you save the images in the database? They should be saved in the file system, outside of the webroot directory like in APP/ media for example. The database is not really a good place for them because they have to go trough the database connection which slows the whole process down. The method for downloading them should make use of the cake core media view. You can also do access controll in this method if that was the reason why you've choosen a db to make them not availible in the file system. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
Faifas, I'll try your suggestion. Thanks. Burzum, there are many good reasons a developer might save images in the database. See here for more information: http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html#1 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
It seems that adding Configure::write('security', 'medium'); to my controller does not help. :-\ I'm wondering if what I want to do is not possible by Cake design. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
Another update. I tried inserting this code into my image_upload controller. function beforeFilter() { Configure::write('Security.level', 'medium'); } After inserting this code, the session still breaks, but all of the images load correctly. So now it's half-working. Hopefully I'm onto something ... I'm still learning how all of this works! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
Daffy, you may also want to add this to your beforeFilter(): Configure::write('Session.timeout', '600'); It will make session to last longer, hopefully, enough to load images. Cheers, Faifas On Wed, Mar 18, 2009 at 18:12, Daffy jon.bennet...@gmail.com wrote: Another update. I tried inserting this code into my image_upload controller. function beforeFilter() { Configure::write('Security.level', 'medium'); } After inserting this code, the session still breaks, but all of the images load correctly. So now it's half-working. Hopefully I'm onto something ... I'm still learning how all of this works! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
Thanks for the suggestion, Faifas. Unfortunately it does not seem to make a difference, although I was hopeful it would because it makes sense. Even when I set the timeout to 6 (after trying your suggested 600) it still logs the user out. The images I'm loading in my test are small. Around 10kb each, 3 images. Only 30kb. The comments in Cake's core say: CakePHP session IDs are also regenerated between requests if 'Security.level' is set to 'high'. So I think this might be the cause of the issue. I wonder if there is some way I can Configure::write in my controller to not regenerate the session ID between requests. Thanks, Jon On Mar 18, 12:46 pm, Aivaras faifas1...@gmail.com wrote: Daffy, you may also want to add this to your beforeFilter(): Configure::write('Session.timeout', '600'); It will make session to last longer, hopefully, enough to load images. Cheers, Faifas On Wed, Mar 18, 2009 at 18:12, Daffy jon.bennet...@gmail.com wrote: Another update. I tried inserting this code into my image_upload controller. function beforeFilter() { Configure::write('Security.level', 'medium'); } After inserting this code, the session still breaks, but all of the images load correctly. So now it's half-working. Hopefully I'm onto something ... I'm still learning how all of this works! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Keeping session alive when loading images from database
Cake version: 1.1 CAKE_SECURITY level: high Hello everyone. I hope this question is not too complicated. I've been struggling with an issue for a couple of days. I have an image upload script that uploads images to a MySQL database, storing it as a BLOB, also creating a thumbnail for the image when it does this. I developed this with the help of the following sites: 1. http://cakebaker.42dh.com/2006/04/15/file-upload-with-cakephp/ 2. http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html#1 Downloading an image works fine (using Content-Disposition header) but when trying to load more than one thumbnail in a view, my Cake session is destroyed and the user is automatically logged out when they attempt to load another page. I don't have this problem when the Cake security level is set to MEDIUM, but I'm trying to keep it working with a security level of HIGH. Here is my controller: = // this is for image uploading. function add() { // Read person from ID from session variable $lastPerson = $this-Session-read('lastPersonId'); // is_uploaded_file is used for security. // getimagesize is to verify the user uploads an image file type, also for security. if (!empty($this-params['form']) is_uploaded_file($this- params['form']['ImageUpload']['tmp_name']) getimagesize($this-params['form']['ImageUpload'] ['tmp_name']) != false) { $fileData = fread(fopen($this-params['form']['ImageUpload'] ['tmp_name'], r), $this-params['form'] ['ImageUpload']['size']); // get the thumb image info. $thumb = getimagesize($this-params['form']['ImageUpload'] ['tmp_name']); // assign thumb variables. $image_type = $thumb['mime']; $imgfp = fread(fopen($this-params['form']['ImageUpload'] ['tmp_name'], 'rb'), $this-params['form']['ImageUpload']['size']); $image_width = $thumb[0]; $image_height = $thumb[1]; $image_size = $thumb[3]; // create a second variable for the thumbnail. $thumb_data = file_get_contents($this-params['form'] ['ImageUpload']['tmp_name']); // get the aspect ratio for the thumbnail (height / width). $aspectRatio=(float)($thumb[0] / $thumb[1]); // thumbnail height. $thumb_height = 100; // the thumb width is the thumb height/aspect ratio. $thumb_width = $thumb_height * $aspectRatio; // get the image source, apply to variable $src. $src = imagecreatefromstring($thumb_data); // create the destination image. $destImage = ImageCreateTrueColor($thumb_width, $thumb_height); // copy and resize the $src image to the destination image. ImageCopyResampled($destImage, $src, 0,0,0,0, $thumb_width, $thumb_height, $thumb[0], $thumb[1]); // start output buffering. ob_start(); // export the image. imageJPEG($destImage); // stick the image content in the variable $image_thumb $image_thumb = ob_get_contents(); // clean up the output buffer and turn off the output buffering. ob_end_clean(); $this-params['form']['ImageUpload']['thumb'] = $image_thumb; // $size = size of the image file. Set a maximum size. $size = $this-params['form']['ImageUpload']['size']; // 200 = 2MB. $maxsize = 200; // is the image less than this max value? If so, continue with the save. if($size $maxsize) { $this-params['form']['ImageUpload']['data'] = $fileData; // insert the user's ID into the file upload table so we know who it belongs to. $this-params['form']['ImageUpload']['person_id'] = $lastPerson; $this-ImageUpload-save($this-params['form'] ['ImageUpload']); // save successful, so let's confirm the upload and redirect the user. $this-Session-setFlash('Upload successful.'); $this-redirect('tongue_uploads/add'); } else { // if the image is too big, show this error. $this-Session-setFlash('The file was too big.'); } } elseif (!empty($this-params['form']) getimagesize($this- params['form']['ImageUpload']['tmp_name']) == false) { // if the file is not an image type, show this error. $this-Session-setFlash('Please upload the correct file type.'); } $conditions =
Re: Keeping session alive when loading images from database
From core.php CakePHP session IDs are also regenerated between requests if 'Security.level' is set to 'high'. That's expected behavior. Setting it to medium is what I've done in my app since I make heavy use of concurrent ajax calls. Regards, Alfredo On Tue, Mar 17, 2009 at 2:03 PM, Daffy jon.bennet...@gmail.com wrote: Cake version: 1.1 CAKE_SECURITY level: high Hello everyone. I hope this question is not too complicated. I've been struggling with an issue for a couple of days. I have an image upload script that uploads images to a MySQL database, storing it as a BLOB, also creating a thumbnail for the image when it does this. I developed this with the help of the following sites: 1. http://cakebaker.42dh.com/2006/04/15/file-upload-with-cakephp/ 2. http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html#1 Downloading an image works fine (using Content-Disposition header) but when trying to load more than one thumbnail in a view, my Cake session is destroyed and the user is automatically logged out when they attempt to load another page. I don't have this problem when the Cake security level is set to MEDIUM, but I'm trying to keep it working with a security level of HIGH. Here is my controller: = // this is for image uploading. function add() { // Read person from ID from session variable $lastPerson = $this-Session-read('lastPersonId'); // is_uploaded_file is used for security. // getimagesize is to verify the user uploads an image file type, also for security. if (!empty($this-params['form']) is_uploaded_file($this- params['form']['ImageUpload']['tmp_name']) getimagesize($this-params['form']['ImageUpload'] ['tmp_name']) != false) { $fileData = fread(fopen($this-params['form']['ImageUpload'] ['tmp_name'], r), $this-params['form'] ['ImageUpload']['size']); // get the thumb image info. $thumb = getimagesize($this-params['form']['ImageUpload'] ['tmp_name']); // assign thumb variables. $image_type = $thumb['mime']; $imgfp = fread(fopen($this-params['form']['ImageUpload'] ['tmp_name'], 'rb'), $this-params['form']['ImageUpload']['size']); $image_width = $thumb[0]; $image_height = $thumb[1]; $image_size = $thumb[3]; // create a second variable for the thumbnail. $thumb_data = file_get_contents($this-params['form'] ['ImageUpload']['tmp_name']); // get the aspect ratio for the thumbnail (height / width). $aspectRatio=(float)($thumb[0] / $thumb[1]); // thumbnail height. $thumb_height = 100; // the thumb width is the thumb height/aspect ratio. $thumb_width = $thumb_height * $aspectRatio; // get the image source, apply to variable $src. $src = imagecreatefromstring($thumb_data); // create the destination image. $destImage = ImageCreateTrueColor($thumb_width, $thumb_height); // copy and resize the $src image to the destination image. ImageCopyResampled($destImage, $src, 0,0,0,0, $thumb_width, $thumb_height, $thumb[0], $thumb[1]); // start output buffering. ob_start(); // export the image. imageJPEG($destImage); // stick the image content in the variable $image_thumb $image_thumb = ob_get_contents(); // clean up the output buffer and turn off the output buffering. ob_end_clean(); $this-params['form']['ImageUpload']['thumb'] = $image_thumb; // $size = size of the image file. Set a maximum size. $size = $this-params['form']['ImageUpload']['size']; // 200 = 2MB. $maxsize = 200; // is the image less than this max value? If so, continue with the save. if($size $maxsize) { $this-params['form']['ImageUpload']['data'] = $fileData; // insert the user's ID into the file upload table so we know who it belongs to. $this-params['form']['ImageUpload']['person_id'] = $lastPerson; $this-ImageUpload-save($this-params['form'] ['ImageUpload']); // save successful, so let's confirm the upload and redirect the user. $this-Session-setFlash('Upload successful.'); $this-redirect('tongue_uploads/add'); } else { // if the image is too big, show this error. $this-Session-setFlash('The file was too big.');
Re: Keeping session alive when loading images from database
Thanks for your swift response. I'm still relatively new to Cake so this might be a stupid question, but, is it possible to tell CakePHP to use a medium security for one section of the web site, and high security for the rest of it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
Ummm, not that I know of. Regards, Alfredo On Tue, Mar 17, 2009 at 2:38 PM, Daffy jon.bennet...@gmail.com wrote: Thanks for your swift response. I'm still relatively new to Cake so this might be a stupid question, but, is it possible to tell CakePHP to use a medium security for one section of the web site, and high security for the rest of it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Keeping session alive when loading images from database
Hey, Why not trying this: Configure::write('security', 'medium')? I believe it would work. Best wishes, Faifas On Tue, Mar 17, 2009 at 20:52, Alfredo Quiroga-Villamil laww...@gmail.comwrote: Ummm, not that I know of. Regards, Alfredo On Tue, Mar 17, 2009 at 2:38 PM, Daffy jon.bennet...@gmail.com wrote: Thanks for your swift response. I'm still relatively new to Cake so this might be a stupid question, but, is it possible to tell CakePHP to use a medium security for one section of the web site, and high security for the rest of it? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups CakePHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---