Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Blog Module /

Discuss the Blog Module.

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

Using Uploadify on the Front End Blog Entry Form


Reply


8 Posts   1573 Views

Avatar
juneallison

Community Member, 108 Posts

23 July 2011 at 3:48am

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!

Avatar
nekrasov

Community Member, 4 Posts

23 July 2011 at 4:16am

Edited: 23/07/2011 4:43am

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!

Avatar
juneallison

Community Member, 108 Posts

23 July 2011 at 7:02am

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!

Avatar
nekrasov

Community Member, 4 Posts

23 July 2011 at 8:23am

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: [url]http://doc.silverstripe.org/sapphire/en/changelogs/2.4.5[/url]

I hope you find this information helpful.

Avatar
juneallison

Community Member, 108 Posts

24 July 2011 at 5:31am

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!

Avatar
juneallison

Community Member, 108 Posts

26 July 2011 at 3:46am

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!

Avatar
nekrasov

Community Member, 4 Posts

27 July 2011 at 4:22am

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!

Avatar
juneallison

Community Member, 108 Posts

27 July 2011 at 4:47am

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

I really appreciate your help!