News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

CRC32, MD5 and Sha-1 in attachments view

Started by L'AltroWeb, October 15, 2010, 02:39:58 PM

Previous topic - Next topic

L'AltroWeb

Display.template.php:
Search:
                echo '
                                        <a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" />&nbsp;' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . '.)<br />';
            }

Change to:
                echo '
                                        <a href="' . $attachment['href'] . '"><img src="' . $settings['images_url'] . '/icons/clip.gif" align="middle" alt="*" border="0" />&nbsp;' . $attachment['name'] . '</a> (', $attachment['size'], ($attachment['is_image'] ? ', ' . $attachment['real_width'] . 'x' . $attachment['real_height'] . ' - ' . $txt['attach_viewed'] : ' - ' . $txt['attach_downloaded']) . ' ' . $attachment['downloads'] . ' ' . $txt['attach_times'] . ')';
                                        foreach (glob($modSettings['attachmentUploadDir']."/".$attachment['id']."_*") as $filehash) {
                                            echo '<span class="smalltext"> &gt; CRC32: '.str_pad(strtoupper(dechex(crc32(file_get_contents($filehash)))), 8, '0', STR_PAD_LEFT).'<br />&gt; MD5: '.strtoupper(md5_file($filehash)).' &gt; SHA-1: '.strtoupper(sha1_file($filehash)).'</span><hr />';
                                        }
            }

That is all :)

Demo: http://www.darkwolf.it/news-board/aggiornamento-10-novita-a-sito-forum-e-gallery/msg2759/#msg2759


L'AltroWeb

I think (but, in realty, i can't be sure) isn't a big problem to load this value at every run.
I've test speed page (also in a post with "more" attachments) and it seems to load fine (without any problem) :|


SlammedDime

Have you tested it with a server load of 10 users at once? 100? 1000?

Say you have 30 people concurrently looking at a topic that has 10 attachments... that's 300 file system calls to get some hashes, and at 3 hashings per file, thats 900 function calls... definitely poor for performance.

Running glob like that will bog down the filesystem in no time with more and more users.  It would be better, and less intensive, to store the data in the database, and pull it out on the query that fetches attachments.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

L'AltroWeb

I've this same code in download area (with tinyportal, and many file to big dimensions: http://www.tinyportal.co.uk/index.php?topic=33034.msg265175#msg265175) and i still haven't problems with my server/hosting (but i think you're right - my forum isn't very populated).
---
Thanks (to both) for your replies :)

Advertisement: