1 of 6
1
LG SAEF File Upload…. Throwing my hat into the ring
Posted: 12 June 2008 11:03 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

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..

File Attachments
lg-saef-file-upload-1.0.0.zip  (File Size: 9KB - Downloads: 224)
 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 13 June 2008 05:50 PM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

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

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 13 June 2008 06:05 PM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

Hey Mark,

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

Cheers

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 13 June 2008 06:17 PM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  6543
Joined  04-15-2006

Hiya,

Thanks will go and check now.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!! (16)
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 14 June 2008 12:48 AM   [ Ignore ]   [ # 4 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  246
Joined  04-12-2008

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

 Signature 

Designchuchi | Twitter

URL Field Extension
Required Category Extension
DC FreeForm GeoIP Extension

Profile
 
 
Posted: 14 June 2008 05:08 PM   [ Ignore ]   [ # 5 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

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

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 18 June 2008 06:14 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  344
Joined  05-22-2005

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.

Profile
 
 
Posted: 18 June 2008 06:28 AM   [ Ignore ]   [ # 7 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

Yeah those features are planned for the future…

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 18 June 2008 05:30 PM   [ Ignore ]   [ # 8 ]  
Summer Student
Avatar
Total Posts:  10
Joined  05-13-2008

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

Profile
 
 
Posted: 18 June 2008 05:38 PM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

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:

/**
    * 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;
    
}

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 18 June 2008 05:43 PM   [ Ignore ]   [ # 10 ]  
Summer Student
Avatar
Total Posts:  10
Joined  05-13-2008

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

Profile
 
 
Posted: 18 June 2008 05:49 PM   [ Ignore ]   [ # 11 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

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

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 June 2008 07:23 AM   [ Ignore ]   [ # 12 ]  
Research Assistant
RankRankRank
Total Posts:  344
Joined  05-22-2005

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.

Profile
 
 
Posted: 19 June 2008 08:24 AM   [ Ignore ]   [ # 13 ]  
Summer Student
Avatar
Total Posts:  10
Joined  05-13-2008

hmm, didn’t experience that ^

but now it won’t add the upload file directory tag “{filedir_2}” unless I comment out the added line from above….

Profile
 
 
Posted: 19 June 2008 08:29 AM   [ Ignore ]   [ # 14 ]  
Research Assistant
RankRankRank
Total Posts:  344
Joined  05-22-2005

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!

Profile
 
 
Posted: 19 June 2008 04:47 PM   [ Ignore ]   [ # 15 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

Hey do you guys have PHP errors turned on?

A blank screen usually means an issue with the language file so I’ll check that out. Can you try browsing to the language file directly and see what happens?

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 June 2008 04:49 PM   [ Ignore ]   [ # 16 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

Oh and what version of PHP are you guys using?

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 June 2008 04:57 PM   [ Ignore ]   [ # 17 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1076
Joined  01-24-2006

Ok guys… I have just uploaded the latest version I have been using on my site. Try that one out and let me know how you go…

 Signature 

VOTE FOR LG Addons in the Mashable Open Web Awards!


Newism - Newcastle Web Design & Development


LG Better Meta now w/ Sitemap Meta & XML Generator | LG Polls | LG .htaccess Generator

Profile
 
 
Posted: 19 June 2008 07:22 PM   [ Ignore ]   [ # 18 ]  
Summer Student
Avatar
Total Posts:  10
Joined  05-13-2008

latest is giving me various output like this at top of every page on site:

Array
(   [hidden_fields] => Array
      (
        [ACT] => {AID:Weblog:insert_new_entry}
        [RET] => http://localhost/index.php/daily_photo/upload/
        [PRV] => {PREVIEW_TEMPLATE}
        [URI] => /daily_photo/upload/
        [XID] =>
        [return_url] => daily_photo/index
        [author_id] => 1
        [weblog_id] => 7
        [field_ft_6] => none
        [field_ft_7] => none
        [site_id] => 1
      )

  [action] => http://localhost/index.php/daily_photo/upload/
  [id] => entryform
  [secure] => 1
  [enctype] =>
  [onsubmit] =>
)

Array
(   [hidden_fields] => Array
      (
        [ACT] => {AID:Search:do_search}
        [XID] =>
        [RP] => search/results
        [NRP] =>
        [RES] =>
        [status] =>
        [weblog] =>
        [search_in] => everywhere
        [where] => all
        [site_id] => 1
      )

  [action] =>
  [id] =>
  [secure] => 1
  [enctype] =>
  [onsubmit] =>
)

using php 5.2.1 and still not adding the upload directory tag also. wink browsing directly to the lang file provides a blank page.

Profile
 
 
   
1 of 6
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64909 Total Logged-in Users: 46
Total Topics: 81853 Total Anonymous Users: 29
Total Replies: 440064 Total Guests: 224
Total Posts: 521917    
Members ( View Memberlist )