Jonathan Morgan

ExpressionEngine: adding easy file upload to SAEF

Apologies to my readers who are less than interested with tech and code related posts. I’m plotting a way to separate my posts, so that you won’t be subjected to this much longer. Thanks for your patience!

This post continues from yesterday, since I ran into problems trying to implement the easy file upload in the SAEF (Stand Alone Entry Form).  After much searching in the forums, and Google, I discovered how I could get this running smoothly.  The following assumes that you have already installed Mark Huot’s File Upload Extension and have it up and running through your control panel.

  1. Modify your mod.weblog_standalone.php (found at /system/modules/weblog/mod.weblog_standalone.php) so that instead of reading:
    $data = array(
    'hidden_fields' => $hidden_fields,
    'action' => $RET,
    'id' => 'entryform'
    );

    It reads:
    $data = array(
    'hidden_fields' => $hidden_fields,
    'action' => $RET,
    'id' => 'entryform',
    'enctype' => 'multipart/form-data'
    );

    For more information read this article by Chad Crowell.

  2. Find out the Field_ID, for the custom field that you are wanting to add to, in the Control Panel by going to Admin > Utilities > SQL Manager > Manage Database Tables and browsing the exp_weblog_fields table
  3. Add the following code to your SAEF (below the {/custom_fields} tag), exchanging 9 for your unique Field_ID

    <label for="content">File Upload:</label>
    <input class="required" id="file_content" title="Please upload a file. This field is required." name="field_id_9_img[]" type="file" class='file' />
    <input type="hidden" value="" class="file" name="field_id_9"/>
    <input type="hidden" value="file" class="file" name="field_ft_9"/>
  4. And, finally, test to see if it works properly before going live with a client’s site.

For more on this, please take a look at the following links from the EE forum:

ExpressionEngine: File Upload extension

Until yesterday I felt that the biggest weakness in using ExpressionEngine as a Content Management System was its roundabout way of handling image and file uploads. For my less tech-savvy clients this was particularly troublesome because it meant that some of them felt they were unable to upload images themselves.

However yesterday I discovered Mark Huot’s File Upload Extension. The extension makes managing files much easier, giving users a simple ‘browse’ button for searching their hard drive, and even manages resizing and cropping site wide (without users ever having to face questions like “would you like to resize your image,” or “would you like to delete the original?”

I did, however, have to customize the extension slightly due to the fact that images with a .jpg file extension were pixelating. After a quick search of the forums I discovered that if I replaced the following code (in the extension file, under the heading ‘Write File’):

if(@imagegif($dst_img, $dst) !== false) {}
else if(@imagejpeg($dst_img, $dst) !== false) {}
else if(@imagepng($dst_img, $dst) !== false) {}

With:
if(@imagejpeg($dst_img, $dst, 90) !== false) {}
else if(@imagegif($dst_img, $dst) !== false) {}
else if(@imagepng($dst_img, $dst) !== false) {}

I could avoid this pixelation and display better quality images.

Update:
I’ve been using this extension on a Windows 2003 server and had some difficulties with the extension accepting the server paths. This post helped me resolve the issue.

subscribe