Hello all,
This thread [ Mark Huot ] have got too long and I decided to start a new here.
I’d like to discuss advanced topics such as customizations and improvements.
I think it is a great extension and I believe it has a lot of potential.
As of the time of this post, Mark Huot’s file Extension is at version 3.1.1.
The extension can be downloaded here: http://docs.markhuot.com/ee/extensions/file/
As I mentioned above, I’m trying to discuss advanced usage of the extension. Please don’t post things like “It doesn’t work for me” because the extension does work just fine.
If there is something you need improved be detailed in your post. Try to explain what, where, and when.
This thread could grow big just like the original. I’m just hoping we can keep it clean and organized.
For those who come here for basic questions read this before you ask:
1. Enable the extension Admin › Utilities › Extensions Manager
2. Create or Edit an Upload Destination Go to Admin › Weblog Administration › File Upload Preferences and Create or Edit an Upload Destination. This is where the extension’s settings are configured.
3. Configure. Change the settings for this particular Upload Destination. Look here for instructions
4. Create a custom field. Go to Admin › Weblog Administration › Field Groups and create a custom field to be used for uploading images or files. Select “File” under “Field Type” and to the right select the Upload Destination for this field.
If “Keep Original” is set to “yes”, you will have two image files. Otherwise only the resized version.
There are two ways of getting data from this extension.
1. Single variable.
{exp:weblog:entries weblog="{weblog_name}"}
{custom_field_name}
{custom_field_name_thumb}
{/exp:weblog:entries}
2. Variable pair.
{exp:weblog:entries weblog="{weblog_name}"}
{custom_field_name}
{if count == 1}
There are {total_results} image{if total_results > 1}s{/if}
{/if}
Image {count}
Original Image: {file_url}
Thumbnail Image: {file_thumb_url}
{/custom_field_name}
{/exp:weblog:entries}
• If “Keep Original” setting is set to “yes”, then {file_url} contains the original file while {file_thumb_url} contains the thumbnail version. If “Keep Original” == “no”, then {file_url} contains the resized version and {file_thumb_url} is disabled.
• Use conditionals to limit the output. Everything within the paired tags will loop as many times as there are images. So you could say “output this only on the first loop”. For example
{if count == 1} this will only appear once {/if}
• If this is not clear enough and you still don’t understand how to use this extension, please post your questions here: http://ellislab.com/forums/viewthread/38997
This is a summary of this thread
1. Get the extension to work.
2. We need the SAEF to have an enctype of “multipart/form-data”, which it does not by default. So download and install Jermaine M’s SAEF Enctype Extension from this post in the original ”File” thread.
3. Modify SAEF Enctype extension for your needs. It wouldn’t work out of the box for me (mdesign) because my SAEF has a dynamic and always different “URI” so I changed the options to look for the weblog id of the weblog where I’m storing files. This is the line you’ll need to modify in one way or another (appx line 96):
ORIGINAL CODE(looking at the URI hidden field)
if (isset($options['hidden_fields']['URI']) && $options['hidden_fields']['URI']=='/post/images/')
$options['enctype']='multi';
mdesign’s MOD (changing which hidden field to look at)
if (isset($options['hidden_fields']['weblog_id']) && $options['hidden_fields']['weblog_id']=='19')
$options['enctype']='multi';
4. Get the field_id number for your custom field.
5. Build SAEF as normal.
6. Paste in something like (at the most minimal): example field id = 112
<input type="hidden" name="field_id_112" value="" />
<input name="field_id_112_img[]" type="file" class="file" />
If I add 2 or more images, I just get the first one repeated over and over.
So if I add 4 pics I just get the first one 4 times
<pre><code> {exp:weblog:entries weblog="missions" category="7"} {missiongallery} {if {count == 1} There are {total_results} image{if total_results > 1}s{/if} {/if}
” title=”Mongolia”]{missiongallery} {/missiongallery}
{/exp:weblog:entries}[/code]
Scap this post, seems I got it working <pre><code>{missiongallery} {if {count == 1} There are {total_results} image{if total_results > 1}s{/if} {/if}
” title=”Mongolia”]{file_thumb_url} {/missiongallery}
{/exp:weblog:entries}[/code]
I like this extension so much that I will use until EE has this functionality built in. And since EE 2.0 has been delayed I will be using this extension a lot longer.
I have a few suggestions for improving this extension. Some of this were already pointed out in other posts but I’m creating a list here so we can discuss the possibilities of getting this things done.
I’m listing feature requests for the file extension in priority order (in my opinion)
1. Add max width and max height to the extension settings so it doesn’t use the max width and max height of the Module preferences. The problem with the current setup is that once enabled, the upload destination can’t be used by the default upload utility because images will be resized to the max dimensions set.
2. Add display order: once files have already been uploaded there is no way to change the order they are displayed. One has to delete them all and re upload in the order they wish. Adding this feature we can just update the order next to each image.
3. Add title and description: it would be nice to have a title and a description for each image. I can see the complication with this but I think we serialize the contents of the field for storage.
4. Improve resized image quality: there seems to be a bug on how the thumbs are created. According to other users of the extension, the resized image is outputed as a gif while the file extension is the same as the uploaded file. It would be a greate feature to be able to choose how thumbnails will be generated, i.g. image type, quality, etc.
5. Browse uploaded images: it should give the option of using images that have already been uploaded. Perhaps a popup displaying a a list of names/thumbnails of images already in the upload directory.
I’m going to look more in depth what it takes to make these changes and I’ll post my thoughts here.
If Mark Huot comes around please let us know what you think about this feature requests.
Making Improvements
1. Add max width and max height 2. Add display order 3. Add title and description 4. Improve resized image quality
below I am speculating the solutions but I haven’t tried them yet.
1.
Need to add 2 input fields in edit_upload_pref() method
$r.= '<tr>';
$r.= '<td class="tableCellTwo label"><span class="defaultBold"><label for="mh_file_img_max_width">Max Width</label></span></td>';
$r.= '<td class="tableCellOne"><input type="text" name="mh_file_img_max_width" value="'.(($this->img_max_width) ? $this->img_max_width : '').'" ></td>';
$r.= '</tr>';
$r.= '<tr>';
$r.= '<td class="tableCellTwo label"><span class="defaultBold"><label for="mh_file_img_max_width">Max Height</label></span></td>';
$r.= '<td class="tableCellOne"><input type="text" name="mh_file_img_max_height" value="'.(($this->img_max_height) ? $this->img_max_height : '').'" ></td>';
$r.= '</tr>';
update modify_post() method so $file_field[‘max_width’] becomes $file_field[‘img_max_width’] and $file_field[‘max_height’] becomes $file_field[‘img_max_height’]
2. and 3.
would have to add three text fields one for order, one for title, one for description.
modify_post() method has to be changed so that:
• all this information is organized into nested arrays. For example,
$custom_field_8 = array(
array(
file_name = "myImage-1",
file_ext = "jpg",
thumb_name = "myImage-1_thumb",
thumb_ext = "jpg",
order = 1,
title = "My Image no 1",
description = "This is my image 1 description"
),
array(
file_name = "myImage-2",
file_ext = "jpg",
thumb_name = "myImage-2_thumb",
thumb_ext = "jpg",
order = 2,
title = "My Image no 2",
description = "This is my image 2 description"
),
array(
file_name = "myImage-3",
file_ext = "jpg",
thumb_name = "myImage-3_thumb",
thumb_ext = "jpg",
order = 3,
title = "My Image no 3",
description = "This is my image 3 description"
)
);
• this is then serialized and stored. • next time this custom field is requested, this data is unserialized and displayed.
4. I’m not sure the fix but there is hack others have posted and I put it here for easy accessibility.
On line 1028 of ext.mh_file_ext.php version 3.1.1
// =============================================
// Write File
// =============================================
@touch($dst);
if(@imagegif($dst_img, $dst) !== false) {}
else if(@imagejpg($dst_img, $dst) !== false) {}
else if(@imagepng($dst_img, $dst) !== false) {}
Modify it so imagejpg is first, then you can pass the jpeg quality as third parameter:
// =============================================
// Write File
// =============================================
@touch($dst);
if(@imagejpeg($dst_img, $dst, 75) !== false) {}
else if(@imagepng($dst_img, $dst) !== false) {}
else if(@imagegif($dst_img, $dst) !== false) {}
any critics?
not yet. I drew this out from thought in an a couple of minutes. It will take me time to go over the whole extension and make appropriate modifications. I just hoped that Mark Huot himself would oversee this or at least approve us from modifying his extension if he doesn’t have the time to do so.
1. Add max width and max height to the extension settings so it doesn’t use the max width and max height of the Module preferences. The problem with the current setup is that once enabled, the upload destination can’t be used by the default upload utility because images will be resized to the max dimensions set.
I’m not sure I understand this one. You can make any number of different upload directories with different preferences, can’t you? And then you can assign different custom fields to different upload directories which can have the exact resizing/thumb quality preferences you require. Or are you talking about something else?
1. Add max width and max height to the extension settings so it doesn’t use the max width and max height of the Module preferences. The problem with the current setup is that once enabled, the upload destination can’t be used by the default upload utility because images will be resized to the max dimensions set.
Let me try to explain better.
By default, uploads are done through EE uploads module. Max width and Max height taken in consideration as the upload limits.
The file extension does not provide a Max thumb width and a Max thumb height. Instead it uses the values of Upload Module Max width and Max height to create thumbnails.
This is a big conflict. If I set Max width and Max height to be 640x480 as the maximum upload dimensions, the file extension will use those values for thumbnails. In order to get 100x100 thumbnails I need to set Max width and Max height to 100x100 which then makes uploading files “the default way” useless.
Look at the attached image. The idea is that we add two text fields to the extension that will control the thumbnail/resizing dimensions independent of the module preferences. This way we can still upload images the default way and we can upload images through the file extension using the same Upload Directory.
Of course we can get around this by creating more upload directories, one only for the default upload module and one only for the file extension. They may as well point to the same directory, but this way they don’t conflict.
This feature request will not affect the functionality of the extension but allow for less upload directories to be created since we can setup one upload directory that has settings for both the default upload module and the file extension independently.
The image below suggests what I’m trying to say
As mentioned by Forrest Anderson on Mark Huot,
this extension should also look for files that have already been uploaded. As of now you must always upload a file even if it already exists.
Giving this ability will save a lot of disk space by lessening the chance of duplicate images.
Dave_H-the extension isn’t being actively developed by the author any longer. To make these changes it looks like you’re going to have to modify the extension yourself/specifically get somebody to do it.
Edit–I see this was discussed before:
I just hoped that Mark Huot himself would oversee this or at least approve us from modifying his extension if he doesn’t have the time to do so
He hasn’t posted since February 26, but he did visit the forum today. I just wouldn’t count on it at this point.
Right. I guess We have to do it. I had planned in doing it but I haven’t got the time yet. Meanwhile we can add to the list or improve on the thinking. I’ll let you all know when I start working on it.
On the previous post #5 I was speculating on how some of this will be implemented. Some of them, such as browsing images on the server, require the extension to be heavily modified. I don’t think is a good idea to rewrite the extension from scratch since EE 2.0 is coming with a file manager. But I’ll take a look at the other ones.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.