1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » Using Uploadify on the Front End Blog Entry Form
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 1081 Views |
-
Using Uploadify on the Front End Blog Entry Form

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!
-
Re: Using Uploadify on the Front End Blog Entry Form

23 July 2011 at 4:16am Last edited: 23 July 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!
-
Re: Using Uploadify on the Front End Blog Entry Form

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!
-
Re: Using Uploadify on the Front End Blog Entry Form

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: http://doc.silverstripe.org/sapphire/en/changelogs/2.4.5
I hope you find this information helpful.
-
Re: Using Uploadify on the Front End Blog Entry Form

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 32MThe 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!
-
Re: Using Uploadify on the Front End Blog Entry Form

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!
-
Re: Using Uploadify on the Front End Blog Entry Form

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!
-
Re: Using Uploadify on the Front End Blog Entry Form

27 July 2011 at 4:47am
Thank you!!! This works and is all that I needed.
I really appreciate your help!
| 1081 Views | ||
|
Page:
1
|
Go to Top |

