Salesforce provides an example of an after insert trigger in the following link http://help.salesforce.com/HTViewSolution?id=000181538 . Here is the answer they provide.
A trigger can be written on Attachment using Force.com IDE or ANT.
A sample code would be:
trigger SetTitleToAttachment on Attachment (after insert) {
String Title;
Id pId;
for(Attachment att: Trigger.new){
Title=att.Name;
pId=att.ParentId;
}
List<Case> c=[select Id , Title__c from Case where Id=:pId];
//assuming one record is fetched.
c[0].Title__c=Title;
update c[0];
}
}
List c=[select Id , Title__c from Case where Id=:pId];
//assuming one record is fetched. c[0].Title__c=Title;
update c[0];
}
Note: There is no way to write a trigger using the Salesforce.com UI (Portal).