Jump to:

1835 Posts in 1139 Topics by 554 members

Blog Module

SilverStripe Forums » Blog Module » Using Uploadify on the Front End Blog Entry Form

Discuss the Blog Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1395 Views
  • juneallison
    Avatar
    Community Member
    108 Posts

    Using Uploadify on the Front End Blog Entry Form Link to this post

    Hi,

    I recently tried adding this snippet of code:
    new FileUploadField('AttachedImage', 'Upload an image', array (
    'buttonText' => 'Upload an Image')),

    to BlogHolder.php

    This creates the upload button on the front end blog entry form but it doesn't seem to function properly. It lets me select an image but does not actually upload an image. Instead it says no file attached.

    Any suggestions would be great.

    Thanks!

  • nekrasov
    Avatar
    Community Member
    4 Posts

    Re: Using Uploadify on the Front End Blog Entry Form Link to this post

    First you must create a decorator for the blog entries.

    1. Create a file in mysite/code called: BlogEntryDecorator.php and paste the following code:

    class BlogEntryDecorator extends SiteTreeDecorator {
    function extraStatics() {
    return array(
    'has_one' => array(
    'AttachedImage'=>'Image'
    )
    );
    }

    function updateCMSFields(& $fields){
    $fields->addFieldToTab('Root.Content.Image', new ImageField('AttachedImage','Attach an image to this blog entry'));
    }
    }

    2. Add the following line to your _config.php:

    DataObject::add_extension('BlogEntry', 'BlogEntryDecorator');

    3. Add your code to BlogHolder.php file (after the line 231 and before line 240):

    new FileUploadField('AttachedImage', 'Upload an image', array ( 'buttonText' => 'Upload an Image')),


    you can use ImageUploadField instead of FileUploadField (since we want to upload only images):

    new ImageUploadField('AttachedImage', 'Upload an image', array ( 'buttonText' => 'Upload an Image')),


    4. Add the following code to your templates (BlogSummary.ss, BlogEntry.ss, etc.)

    <% if AttachedImage %>
    $AttachedImage.CroppedImage(width-value,height-value)
    <% end_if %>

    5. Before you try, visit your-site.com/dev/build?flush=all

    And you're done!

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Using Uploadify on the Front End Blog Entry Form Link to this post

    Thanks @nekrasov ! But i just tried all of these steps and my upload button on the front end still doesn't work. For a split second I see what looks like a loading bar, but then is disappears and nothing is attached. I did the database flush prior to testing this.

    Any idea where things might be going wrong?

    Thanks!

  • nekrasov
    Avatar
    Community Member
    4 Posts

    Re: Using Uploadify on the Front End Blog Entry Form Link to this post

    To help you better, I need to know:

    1. Which version of Silverstripe you are running?

    2. What is your development environment ? (XAMP, MAMP, WAMP, PHP version)

    3. Versions of Blog Module and Uplodify

    4. Check the memory allocation in php.ini
    search for: max_execution_time, max_input_time, memory_limit, post_max_size, upload_max_filesize
    and try to increase their values.

    I remember that in a recent version of Silverstripe there were problems with the extensions JPG or JPEG (uppercase) when you were trying to upload an image.

    With the release of Silverstripe 2.4.5: Bugfix: Valid file uploads with uppercase extensions blocked from being web accessible

    Check the changelogs: http://doc.silverstripe.org/sapphire/en/changelogs/2.4.5

    I hope you find this information helpful.

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Using Uploadify on the Front End Blog Entry Form Link to this post

    Thanks nekrasov!!

    My answers:

    1. SS 2.4.5
    2. MAMP, PHP 5.3.5
    3. Blog Module 0.4.1, Uploadify - The most recent? I downloaded it this week
    4. This is what I currently have for those items:
    max_execution_time   30   
    max_file_uploads   20   
    max_input_nesting_level   64   
    max_input_time   60   
    memory_limit   32M
    post_max_size   32M
    upload_max_filesize   32M

    The file I was trying to upload had a lowercase .jpg

    I haven't tried increasing any of the PHP values yet. I'll let you know if that helps.

    Thanks!

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Using Uploadify on the Front End Blog Entry Form Link to this post

    Just to give an update I increased the memory limit to 64M and still no luck. Plus the image that I tried is pretty small. I also tried a different test image and got the same result.

    Any additional suggestions would great, thanks!

  • nekrasov
    Avatar
    Community Member
    4 Posts

    Re: Using Uploadify on the Front End Blog Entry Form Link to this post

    Hello juneallison!

    OK, I don't know why you can't upload the image with uplodify.

    But there is another option to achieve this:

    Use the class SimpleImageField
    Summary: SimpleImageField provides an easy way of uploading images to Image has_one relationships.

    Just change the line that you added to BlogHolder.php:

    new FileUploadField('AttachedImage', 'Upload an image', array ( 'buttonText' => 'Upload an Image')),

    with the following:

    new SimpleImageField('AttachedImage', 'Upload an image'),

    That's all!

    I really hope all of this works for you!

  • juneallison
    Avatar
    Community Member
    108 Posts

    Re: Using Uploadify on the Front End Blog Entry Form Link to this post

    Thank you!!! This works and is all that I needed.

    I really appreciate your help!

    1395 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.