We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

LG SAEF File Upload.... Throwing my hat into the ring

Development and Programming

Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Ok guys,

I know it has been attempted many times before (some attempts more successful than others) but I have developed my own SAEF file upload extension.

My extension is super easy to use… just install and add the following code to your SAEF form…

{exp:weblog:entry_form
    weblog = "gallery"
    lg_saef_file_upload = "y"
    lg_saef_file_upload_dir_id = "1"
}
  <input type="file" name="field_id_7" value="" />
  <input type='submit' value='submit' />
{/exp:weblog:entry_form}
  • All required / optional fields are respected
  • File upload prefs are respected
  • Duplicate files are renamed

Simple….

Like I said this has been attempted many times before so I want to get it right…

UPDATE 1 June 23rd 4:49pm

I have tweaked a bit of the code and added the requested edit feature (needs some testing)

So now if you have an edit form you can add a new hidden field that stores the original value. If the file upload element is empty the original value will be used otherwise the extension will try and overide the previous file.

Example:

{exp:weblog:entry_form
    weblog = "gallery"
    lg_saef_file_upload = "y"
    lg_saef_file_upload_dir_id = "1"
}
  <input type="file" name="field_id_7" value="" />
  <input type="hidden" name="field_id_7" value="{custom_field_that_holds_the_data}" />
  <input type='submit' value='submit' />
{/exp:weblog:entry_form}

Note there is no way to delete a file yet.. Hopefully that will be coming soon.

If you are having issues with logging into the cp turn off auto update checking when you install the extension.

Grab the latest download.

UPDATE 2 June 23rd 5:30pm

Ok after a bit more testing I have realised there is no need for the hidden field… It actually causes complications…

Here is a basic edit form:

{exp:weblog:entries entry_id="{segment_1}"}
{exp:weblog:entry_form
    weblog = "upload_test"
    lg_saef_file_upload = "y"
    lg_saef_file_upload_dir_id = "1"
}
<input type="hidden" name="entry_id" value="{entry_id}" />
<input type="hidden" name="entry_date" value="{entry_date format='%Y-%m-%d %g:%i %A'}" />
<input type="text" name="title" value="{title}" />
<div>
<input type="file" name="field_id_224" value="" />
</div>
<div>
<input type="file" name="field_id_225" value="" />
</div>
<input type='submit' value='submit' />
{/exp:weblog:entry_form}
{/exp:weblog:entries}

You will obviously need to edit the field_ids and the weblogs entry loop… but I think we are getting there.

UPDATE 3 June 24th 8:08am

I have uploaded a new version which should crush the member login bug some user have been reporting..

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hi Leevi,

Did drop you a PM this morning. Not sure if you received it or not though?

Would love to get a look at trying this one out if possible.

Best wishes,

Mark

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Hey Mark,

I sent you an email with the extension about an hour ago… I’ll resend 😊

Cheers

       
Mark Bowen's avatar
Mark Bowen
12,637 posts
17 years ago
Mark Bowen's avatar Mark Bowen

Hiya,

Thanks will go and check now.

Best wishes,

Mark

       
gridonic's avatar
gridonic
231 posts
17 years ago
gridonic's avatar gridonic

Haven’t got anything so far either, did you get my PM?

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Here is the first cut of LG SAEF Uploader.

To use all you need to do is add a couple of params to your opening form tag.

lg_saef_file_upload=”y” … Tells the extension to change the form encryption type lg_saef_file_upload_dir_id=” … The upload directory id set in the upload prefs

The set your input name to the id value of the field.

{exp:weblog:entry_form
    weblog = "gallery"
    lg_saef_file_upload = "y"
    lg_saef_file_upload_dir_id = "1"
}
  <input type="file" name="field_id_7" value="" />
  <input type='submit' value='submit' />
{/exp:weblog:entry_form}

The extension is MSM aware, although there is nothing that requires this functionality yet.

There is no support for preview yet… and I’m not sure how to go about SAEF editing. I’ll have to look into it. Any suggestions are welcome.

Cheers Leevi

       
simplyee's avatar
simplyee
104 posts
17 years ago
simplyee's avatar simplyee

Looks great! But having the ability to add it to the edit form would make it usable. At least the ability to delete files like in the file extension.

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Yeah those features are planned for the future…

       
Golfball's avatar
Golfball
10 posts
17 years ago
Golfball's avatar Golfball

Hi Leevi,

Love the extension. If I log out and try to log back in I am getting:

Fatal error: Call to a member function fetch_param() on a non-object in ~\system\extensions\ext.lg_saef_file_upload.php on line 375

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Please disreagrd this comment. It is no longer valid

So your trying to log into the admin?

Quick fix…

Try adding:

if ( ! defined('TMPL')) return $data;

around line 373 in the extension file.

The new function should look like:

<pre><code> /** * Modify the $data parameters before they are processed by the user side form creator * * @param array $data The form data * @return array The form data * @since Version 1.0.0 * @see http://expressionengine.com/developers/extension_hooks/form_declaration_modify_data/ */ function form_declaration_modify_data($data) { global $EXT, $TMPL;

    // -- Check if we're not the only one using this hook
    if($EXT->last_call !== FALSE) $data = $EXT->last_call;

    if ( ! defined('TMPL')) return $data;

    if($TMPL->fetch_param('lg_saef_file_upload') == 'y')
    {
        $data['enctype']='multi';
        $data['hidden_fields']['lg_saef_file_upload'] = 'y';
        $data['hidden_fields']['lg_saef_file_upload_dir_id'] = $TMPL->fetch_param('lg_saef_file_upload_dir_id');
    }
    //$this->_debug($data, FALSE);
    return $data;
}[/code]
       
Golfball's avatar
Golfball
10 posts
17 years ago
Golfball's avatar Golfball

logging in on the front end…but that did it. Thanks!

       
Leevi Graham's avatar
Leevi Graham
1,143 posts
17 years ago
Leevi Graham's avatar Leevi Graham

Just double check your code… I made a quick change..

if ( ! defined('TMPL')) return $data;

should be after the check to see if we are not the only one using this hook

       
simplyee's avatar
simplyee
104 posts
17 years ago
simplyee's avatar simplyee

So I installed the entension, and it was great, worked, until…I had the same issue above, so I modified the file as directed and that was cool, until…I logged out.

Then when I went to log back in to the CP all I had was a blank screen. Cleared everything and still blank. Went to another machine and got the login page. Logged in and, guess what? Blank screen again.

So I logged in to phpmyadmin and deleted the extension there and all is cool, but no upload :(.

Any ideas? It is a great idea, but not good if it crashes everything.

       
Golfball's avatar
Golfball
10 posts
17 years ago
Golfball's avatar Golfball

hmm, didn’t experience that ^

but now it won’t add the upload file directory tag “https://ellislab.com/asset/images/ent-partner-logo/” unless I comment out the added line from above….

       
simplyee's avatar
simplyee
104 posts
17 years ago
simplyee's avatar simplyee

Initially the original file didn’t work. All off the links to member profiles returned errors. When I added the change that was fixed.

But I still get a blank page with either file, the original, or the edited one, after logging out. If the extension is disabled I have no issues. But that’s no good either!

       
1 2 3 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.