Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Attachment Extension 1.4
This discussion has been closed.
Comments
On another note, the image display works well, but...
What would be really good is a good looking row of linked thumbnails along the bottom of the post (perhaps the look and size of the flickr miniatures, the 36 Degrees Flickr Pool is nice, clear and compact). It makes the overall discussion clearer and reduces load for those on dial-up connections (which a lot of non-geeks still have). I can constrain them with CSS but that doesn't reduce load times, a GD-solution would be excellent.
I've had a shot at updating your great Attachments extension to include thumbnailing for picture attachments. Your extension is great, but I will have people on the forum who are not so web-savvy and/or on dial-up connections, so I really wanted an as idiot-proof solution as possible:
- they won't want to upload to/register with another site and figure out how to link it.
- they'll want to take the file they just photographed with the digi-cam and upload it without resizing it first.
- they won't think of other users on dial-up connections when they upload 12 x 450kb pics.
After much trial and error and learning by doing I have it working on my install with thumbnails that link to the image itself. It requires that GDlib 2 is installed server-side. I've added some switches so that if you don't have GDlib you can opt to either display images inline at full size or as textlinks. You can also set thumbnail size. I've set it up to downsize and crop to the thumbnail size, but if you prefer you can take out crop and it will preserve the image aspect ratio (you'll have to adjust your CSS then accordingly).
I also changed some of the IDs for valid XHTML output, added some classes etc. for better styling and some file types too. The GDlib proved to be a bit temperamental to start with but hopefully it shouldn't choke anymore or file extensions in large letters.
Default image types: jpg/jpeg, gif, png
Default file types: zip, rar, doc, rtf, pdf, txt
I expanded your CSS with a fairly clean and sober style which works for me in Firefox and IE6/PC (not tried others yet, I'm sure you guys can improve on it). I wanted it to be low-impact and disrupt the discussion flow as little as possible. The new classes can be used for filetype logos - pdf and doc are included by way of example.
It'll also delete the thumbnail file with the original images.
Feel free to repurpose, perfect, alter and correct, and include what you want in your add-on. I'm a beginner in things PHP so please try it out well before implementing it See Jazzman's Attachment add-on in the Vanilla add-ons directory: download it here.
Lastly, a couple of questions for things I wanted to achieve:
- How can I 'clean' incoming filenames when saving the file, so that characters which are invalid for HTML and co are stripped? Filenames with unusual characters will work but result in validation errors, either in the ID or the url.
- Is there an easy way of reading out the filesize on the fly, without having to store it in a database? It'd be an added info for dial-up users if the tooltip showed title="filename, filesize".
- How to sort the display of attachments so that documents are listed first, then the images? If you upload docs and images alternately it looks rather messy.
Further ideas:- Clicking on the images could call either a pop-up window, or maybe something like thickbox, which takes over user-experience less than lightbox. Dunno if thickbox/jquery conflicts with existing vanilla ajax, or whether part of vanilla's in-built ajax can be used to pop-up the image in an on-page overlay.
- Possibility of unobtrusively watermarking the main image with "forum name / user", e.g. in the lower left corner in a clean (pixel) font.
All comments welcome.But yeah, looks like some pretty nifty work.
I tried $CurrentFileSize = filesize($filename); and then putting $CurrentFileSize into title="" yesterday but I got a function error per file. It was late and I didn't try any further. I probably wasn't using it correctly or in the right context.
for 3, I've commented the code a lot to keep track of things myself :-) The function that outputs the XHTML-list is function GetAttachmentsString from line 188 onwards. I imagine the foreach( $files as $file ) loop needs reading into an array, then filtering according to image/doc type and then processing.
- Added a check if GD library is active (else you get an error)
- Added a check if thumbnails exists before retrieving image dimensions
- Thumbnails will be saved in a seperate folder
- Config settings will now be saved in the conf/settings.php and not in a seperate file
- Created a good readme.html file
the extension should proof, if the filesize is bigger than the default filesize. Now it just starts to upload the file and fails after some amount of time. It creates also a corrupt thumbnail, like this:
http://www.hessen.ru/lussumo/uploads/thumbs/5914.EZB.jpg
uzi: try jazzman's 1-1 version. The original attachment always did that too. I think the upload itself and 'exceed file size' is handled by vanilla, not the add-on. The corrupt thumb was for a file it couldn't upload? that would make sense. That would need checking for (jazzman?). You'll see if you google thumbnailing and GD that lots of people of problems with GD for all number of different reasons.
just tried the new version, edited my comment above. the thumb is for the file it couldn't upload. the file is actually bigger than the "default filesize" in the settings.
edit: I use firefox 1.5.0.3
edit_2: IE 6 is the same thing....
"The file you have attempted to upload (EZB.jpg) is larger than the allowed size: 500kb"
But also this warnings appeared:
Warning: imagecreatefromjpeg(): Unable to access /var/www/s16u38/html/hessen/lussumo/uploads/5914.EZB.jpg in /var/www/s16u38/html/hessen/lussumo/extensions/Attachments/default.php on line 148 Warning: imagecreatefromjpeg(/var/www/s16u38/html/hessen/lussumo/uploads/5914.EZB.jpg): failed to open stream: Permission denied in /var/www/s16u38/html/hessen/lussumo/extensions/Attachments/default.php on line 148 Warning: imagesx(): supplied argument is not a valid Image resource in /var/www/s16u38/html/hessen/lussumo/extensions/Attachments/default.php on line 151 Warning: imagesy(): supplied argument is not a valid Image resource in /var/www/s16u38/html/hessen/lussumo/extensions/Attachments/default.php on line 152 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /var/www/s16u38/html/hessen/lussumo/extensions/Attachments/default.php on line 221 Warning: imagedestroy(): supplied argument is not a valid Image resource in /var/www/s16u38/html/hessen/lussumo/extensions/Attachments/default.php on line 228
With files smaller than 500kb everything works pretty good.
$Configuration['ATTACHMENT_ALLOWED_FILETYPES'] = array ( 'image/gif' => array('gif', 'GIF'), 'image/png' => array('png', 'PNG'), 'image/jpeg' => array('jpg', 'jpeg', 'JPG', 'JPEG'), 'image/pjpeg' => array('jpg', 'jpeg', 'JPG', 'JPEG'), 'application/pdf' => array('pdf', 'PDF'), 'application/x-pdf' => array('pdf', 'PDF'), 'application/msword' => array('doc', 'DOC', 'rtf', 'RTF'), 'application/zip' => array('zip', 'ZIP'), 'application/x-zip-compressed' => array('zip', 'ZIP'), 'application/octet-stream' => array('rar', 'RAR'), 'text/plain' => array('txt', 'TXT'), 'application/x-gzip' => array('gz', 'GZ', 'tar.gz', 'TAR.GZ') );
You can easily add your own. It's not smart to enable all filetypes or block just a few. And people could always zip their attachments and upload the zip file?
if ($this->DisplayImages == true && file_exists($this->UploadPath . $CommentID.'.'.basename($File['name'])) && in_array(...
That catches the trying to make a thumbnail out of no file error.
The time it takes to recognise if the file is too large is the time it takes to upload the file. I guess there's no way of determining how large a file on the user's system is before it's uploaded.
How to determine the filesize of a file on the server without reading in the file was one of my questions earlier.