Wolphie Posted January 1, 2008 Share Posted January 1, 2008 Ok well i'm working on a project and it involves file uploading. I've decided to upload the files to a BLOB field in a database, but to save valuable space i will have to compress it on upload. My main question is what would be the best compression method (Stability and compression size) And what are the functions to compress the file before uploading, and decompressing a file. e.g. if somebody was to upload an image, it would be compressed...written to the database, and when somebody wanted to view it......call it from the database, decompress it and display it. (Same with video media and music) Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/ Share on other sites More sharing options...
Wolphie Posted January 1, 2008 Author Share Posted January 1, 2008 Anybody? Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427581 Share on other sites More sharing options...
duclet Posted January 1, 2008 Share Posted January 1, 2008 Don't bump up the topic so quickly, especially since it is still up on the first page. Anyway, you might want to take a look at some of the gzip functions: gzencode & gzdecode. Look at the PHP manual for more information and details. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427588 Share on other sites More sharing options...
mrdamien Posted January 1, 2008 Share Posted January 1, 2008 The problem with what your asking is that media files are already compressed. The only way to compress them further is by using a better algorithm, or reducing quality. For example a 800x800 bmp is a lot bigger than 800x800 jpeg. But there is no good way to compress a 640x320 mpeg anymore without shrinking it, or using excessive cpu cycles. I mean A LOT of cpu time would be required, simply to save 100kb of space. edit: gzip would be fine for text files, but its not worth it to use on media files. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427593 Share on other sites More sharing options...
Wolphie Posted January 1, 2008 Author Share Posted January 1, 2008 Ok, so aside from media files...what would be the best compression method for image files? Or are you including images within the media phrase. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427598 Share on other sites More sharing options...
mrdamien Posted January 1, 2008 Share Posted January 1, 2008 All I can really say, is convert them to gif/jpeg/png - they really are the best formats. You could also consider limiting the image dimensions to save space. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427602 Share on other sites More sharing options...
Wolphie Posted January 1, 2008 Author Share Posted January 1, 2008 Is is possible to convert images in PHP? ImageMagick i assume. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427606 Share on other sites More sharing options...
mrdamien Posted January 1, 2008 Share Posted January 1, 2008 Actually, I just found someone contributed a function on the php.net site for bmps. http://ca.php.net/manual/en/function.imagecreate.php#53879 My guess is after you make an image with that function, you just output it as something else. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427643 Share on other sites More sharing options...
Daniel0 Posted January 2, 2008 Share Posted January 2, 2008 Don't store the files in the database it self. Store the path to the file instead. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427664 Share on other sites More sharing options...
Wolphie Posted January 2, 2008 Author Share Posted January 2, 2008 Why shouldn't i store them in the database itself? It makes no difference. Storing in a directory, the issue there is that directories have file limits. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427671 Share on other sites More sharing options...
duclet Posted January 2, 2008 Share Posted January 2, 2008 It is faster to get the and doesn't consume as much memory if it is stored in the file system as compared to the database. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427678 Share on other sites More sharing options...
Daniel0 Posted January 2, 2008 Share Posted January 2, 2008 You can store far larger files on the filesystem than in a BLOB and it will just add unnecessary overhead to the MySQL server. It will also make managing the files more difficult for you. Quote Link to comment https://forums.phpfreaks.com/topic/84022-solved-file-compression/#findComment-427685 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.