function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
inanskarinanskar 

How to repeat the form for uploading a file

Hii all, 

I am looking for vf for uploading a file ..I tried and it worked fine but my rquirement  is that i had to take 5 pageblock sections in that each page block section i had to upload a single file my code works fine for one page block section for another it didn't work fine can u guide me the r8 solution

I had also tried with repeat tag by making row="5".. but it didn't work for me ..I'm pasting the code i tried

 

Vf page

------------------------------------------------------------------------------------------------------------------------------------------

<apex:page Controller="sub_FileUploadController" sidebar="false" >

<apex:repeat value="{!userfiledescription}">
<apex:form id="apexform">

<table border="1">

<tr>
<td>


<apex:outputLabel value=""/>
<apex:commandButton onclick="getFileType()" oncomplete="completedfunction();" action="{!page2onLoad}" id="cmdUpload1" value="Upload File">
<apex:commandButton action="{!cancel}" value="Cancel"/>
<apex:commandButton action="{!page2onLoad1}" value="Add More"/>
</apex:commandButton>
</td></tr>


<tr><td>
<apex:outputLabel value="File Description"/></td>
<td>

<apex:inputtext id="ufdescription" value="{!userfiledescription}" />
</td>
</tr>

</table>


<!--Div Code used to display Progress bar image -->
<div id="display1" width="350">

</div>



<apex:inputhidden id="filetypehidden" value="{!filetype}"/>
<apex:inputhidden id="filesizehidden" value="{!filesize}"/>
<apex:inputhidden id="filenamehidden" value="{!filenamehidden}"/>
<input type="hidden" id="submithidden" value="false"/>

<script type="text/javascript">
function getFileType()
{
try
{
var filetype;
var filename;
var filesizeF;
filetype=document.forms['submitform'].elements['file'].value;
document.getElementById('j_id0:apexform:filenamehidden').value=filetype;
filetype=filetype.substring(filetype.indexOf('.',0)+1,filetype.length);

document.getElementById('j_id0:apexform:filetypehidden').value=filetype;
filename=document.forms['submitform'].elements['key'];

if(filetype!='' || filetype!=null)
{
filename.value=filename.value + '.' + filetype;
}
if(navigator.appName!='Microsoft Internet Explorer')
{
try
{
filesizeF=document.forms['submitform'].elements['file'];
<!-- alert(filesizeF.files[0].fileSize);-->
document.getElementById('j_id0:apexform:filesizehidden').value=filesizeF.files[0].fileSize;
//document.getElementById('j_id0:apexform:filesizehidden').value=0;
}
catch(errr)
{
}
}
else
{
document.getElementById('j_id0:apexform:filesizehidden').value=0;
}


if(document.getElementById('j_id0:apexform:filesizehidden').value!=0 && document.getElementById('j_id0:apexform:filesizehidden').value!='undefined' && document.getElementById('j_id0:apexform:filenamehidden').value!=undefined) {
document.getElementById('submithidden').value='true';
return true;
}
else
{
alert('Unable to capture file details..');
document.getElementById('submithidden').value='false';
return false;
}
}
catch(err)
{
alert(err);
return false;
}
}
function completedfunction()
{

try
{
if(document.getElementById('submithidden').value=='true')
{

<!--Code to display Progress bar image -->
var html = '';
html += '<img src="/resource/1323008320000/LoadingImage">';
html += '</img>'
document.getElementById('display1').innerHTML = html;
<!--Code to display Progress bar image end -->
document.forms['submitform'].submit();

} }
catch(err)
{
alert(err);

}
}

</script>

</apex:form>
</apex:repeat>

<form id="submitform"
action="https://s3.amazonaws.com/{!BucketName}"
method="post" enctype="multipart/form-data">

<input type="hidden" name="AWSAccessKeyId" value="{!key}"/>
<input type="hidden" name="policy" value="{!policy}"/>
<input type="hidden" name="signature" value="{!signedPolicy}"/>
<!-- <input type="hidden" name="success_action_redirect" value="https://{!serverURL}/{!AcctID}" /> -->
<input type="hidden" value="{!Filename}" name="key"/>

<apex:outputLabel value="File to upload"/>
<input id="fileid" type="file" size="50" name="file"/>


</form>



</apex:page>

------------------------------------------------------------------------------------------------------------------------------------------------------------

Apex Code

 

public class sub_FileUploadController{
/*
public PageReference Deletefile() {
DeleteObjectRequest request = new DeleteObjectRequest();

BucketName = bucketName;
Key = FileKey;

S3Response response = s3Client.DeleteObject(request);
return null;
}
*/

public PageReference cancel() {
//string queryChild='SELECT Id,parent__c FROM '+ childName + 'Whereid=:' + AcctId + 'LIMIT 1' ;
// SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
Account_Documents__c A = [SELECT id,parent__c from Account_Documents__c where id=:AcctID];
delete a;
return new PageReference('/'+a.parent__c +'/d?retURL=%2F'+ a.parent__c);
//delete childObject;
//return null;
}


public string secret {get;set;}
public string key { get ;set; }
public string BucketName{get;set;}
public string BucketName1{get;set;}
public String serverURL {get;set;}
public String AcctID {get;set;}
public String AcctID1 {get;set;}
public String userFileName{get;set;}
public String userFileDescription{get;set;}
public String userFileDescription1{get;set;}
public String filenamehidden{get;set;}
public string Filename{get;set;}
public string fileType{get;set;}
public Boolean onemore{get;set;}
public Decimal fileSize{get;set;}
//private String AWSCredentialName = 'tvarana7';



//Variable for 2nd form(apexform1)
public string fileType1{get;set;}
public Decimal fileSize1{get;set;}
public String filenamehidden1{get;set;}
public string Filename1{get;set;}
string filedescriptionAPI1;
string filetypeAPI1;
string filesizeinbytesAPI1;
String filenameAPI1;


string filedescriptionAPI;
string filetypeAPI;
string filesizeinbytesAPI;
String filenameAPI;

datetime expire = system.now().addMinutes(40);
String formattedexpire = expire.formatGmt('yyyy-MM-dd')+'T'+
expire.formatGmt('HH:mm:ss')+'.'+expire.formatGMT('SSS')+'Z';


string policy { get {return
'{ "expiration": "'+formattedexpire+'","conditions": [ {"bucket": "'+ BucketName+'" } ,'+

// { "acl": "'+ record.Access__c +'" },'+ '{"success_action_status": "201" },'+ '{"content-type":"'+record.Content_Type__c+'"},'+
// '{"success_action_redirect": "https://'+serverurl+'/'+AcctID+'"},' +
'["starts-with", "$key", ""] ]}'; } }



public sub_FileUploadController()
{
secret='bXrMni3+SWcWU60QDDI37hNjllWCY3syswO0EFbF';
key='AKIAIO55ACM6IO2EACFQ';
BucketName='SUBHASH';
BucketName1='tvarana7';
onemore= False;
}
public String getPolicy() {
return EncodingUtil.base64Encode(Blob.valueOf(policy));
}

public String getSignedPolicy() {
return make_sig(EncodingUtil.base64Encode(Blob.valueOf(policy)),secret);
}


//tester
public String getHexPolicy() {
String p = getPolicy();
return EncodingUtil.convertToHex(Blob.valueOf(p));
}


private String make_sig(string canonicalBuffer,string secret) {
String macUrl ;
String signingKey = EncodingUtil.base64Encode(Blob.valueOf(secret));
Blob mac = Crypto.generateMac('HMacSHA1',blob.valueof(canonicalBuffer),blob.valueof(secret));
macUrl = EncodingUtil.base64Encode(mac);
return macUrl;
}
public String bucketToList {get;set;}

private String ChildName;

public void page2onLoad()
{
system.debug('ACCTID:'+AcctID);
if(AcctID==null || AcctID=='')
{
string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];
System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');



ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');




parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID=childObject.Id;
serverURL =ApexPages.currentpage().getparameters().get('serverURL');




serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename=childObject.id;
filedescriptionAPI=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI=Apexpages.currentpage().getparameters().get('FILENAMEAPI');

}
else
{
String selectfields;
if(filedescriptionAPI!='' && filedescriptionAPI!=null){
selectfields=filedescriptionAPI;}
if(filetypeAPI!='' && filetypeAPI!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI;}
else{
selectfields=filetypeAPI;}
}
if(filesizeinbytesAPI!=null && filesizeinbytesAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI;}
else{
selectfields=filesizeinbytesAPI;}
}
if(filenameAPI!='null' && filenameAPI!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI;}
else{
selectfields=filenameAPI;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI);
system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'');
SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}
else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID + '\'')[0];}

if(filenameAPI!='' && filenameAPI!='null'){
filenameAPI=filenameAPI.replace('\'','');
childObject.put(filenameAPI,userFileName);}
if(filedescriptionAPI!='' && filedescriptionAPI!='null'){
filedescriptionAPI=filedescriptionAPI.replace('\'','');
childObject.put(filedescriptionAPI,userFileDescription);}
if(filetypeAPI!='' && filetypeAPI!='null'){
filetypeAPI=filetypeAPI.replace('\'','');
childObject.put(filetypeAPI,filetype);}
if(filesizeinbytesAPI!='null' && filesizeinbytesAPI!=''){
filesizeinbytesAPI=filesizeinbytesAPI.replace('\'','');
childObject.put(filesizeinbytesAPI,(decimal)((fileSize)));}
system.debug('........................filesizeinbytesAPI fileSize........................'+fileSize);

update childObject;
}
}

//second method

public void page2onLoad1(){


onemore=True;
system.debug('ACCTID1:'+AcctID1);
if(AcctID1==null || AcctID1=='')
{

string parentID=ApexPages.currentpage().getparameters().get('id');
string parentName=ApexPages.currentpage().getparameters().get('ParentObjecName');
parentName=parentName.replace('\'','');
string parentQuery='SELECT Id FROM '+ parentName + ' where id=\'' + parentID +'\'';
System.debug('PARENT QUERY:'+parentQuery);
SObject ParentObject=Database.query(parentQuery)[0];

System.debug('ParentObjectID:' + ParentObject.Id);
ChildName=ApexPages.currentpage().getparameters().get('ChildObjectName');
ChildName=ChildName.replace('\'','');
string queryChild='SELECT Id FROM '+ childName +' LIMIT 1';
string parentRef=ApexPages.currentpage().getparameters().get('ParentRefName');
parentRef=parentRef.replace('\'','');
SObject childObject= Database.query(queryChild)[0].getSObjectType().newSObject();
childObject.put(parentRef,ParentObject.id);
insert childObject;

system.debug('ChildObjectID:' + childObject.id);
AcctID1=childObject.Id;

serverURL =ApexPages.currentpage().getparameters().get('serverURL');
serverURL =serverURL.replace('\'','');
String urlDomain = serverURL.substring(serverURL.indexOf('://')+3,serverURL.indexOf('/services'));
serverURL = urlDomain;

Filename1=childObject.id;
filedescriptionAPI1=Apexpages.currentpage().getparameters().get('FILEDESCRIPTIONAPI');
filetypeAPI1=Apexpages.currentpage().getparameters().get('FILETYPEAPI');
filesizeinbytesAPI1=Apexpages.currentpage().getparameters().get('FILESIZEINBYTESAPI');
filenameAPI1=Apexpages.currentpage().getparameters().get('FILENAMEAPI');
// }
// else
// {
String selectfields;
if(filedescriptionAPI1!='' && filedescriptionAPI1!=null){
selectfields=filedescriptionAPI1;}
if(filetypeAPI1!='' && filetypeAPI1!=null){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filetypeAPI1;}
else{
selectfields=filetypeAPI1;}
}
if(filesizeinbytesAPI1!=null && filesizeinbytesAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filesizeinbytesAPI1;}
else{
selectfields=filesizeinbytesAPI1;}
}
if(filenameAPI1!='null' && filenameAPI1!=''){
if(selectfields!='' && selectfields!=null){
selectfields=selectfields + ',' + filenameAPI1;}
else{
selectfields=filenameAPI1;}
}
if(selectfields!=null && selectfields!=''){
selectfields=selectfields.replace('\'',''); }
system.debug('filenameapi:' + filenameAPI1);

system.debug('thequery:' + 'select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'');
// SObject childObject;
if(selectfields!='' && selectfields!=null){
childObject=Database.query('select id,'+ selectfields +' from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];

}


else{
childObject=Database.query('select id from ' + ChildName + ' where id=\'' + AcctID1 + '\'')[0];}

if(filenameAPI1!='' && filenameAPI1!='null'){
filenameAPI1=filenameAPI1.replace('\'','');
childObject.put(filenameAPI1,userFileName);}
if(filedescriptionAPI1!='' && filedescriptionAPI1!='null'){
filedescriptionAPI1=filedescriptionAPI1.replace('\'','');
childObject.put(filedescriptionAPI1,userFileDescription1);}
if(filetypeAPI1!='' && filetypeAPI1!='null'){
filetypeAPI1=filetypeAPI1.replace('\'','');
childObject.put(filetypeAPI1,filetype1);}
if(filesizeinbytesAPI1!='null' && filesizeinbytesAPI1!=''){
filesizeinbytesAPI1=filesizeinbytesAPI1.replace('\'','');
childObject.put(filesizeinbytesAPI1,(decimal)((fileSize1)));}
system.debug('........................filesizeinbytesAPI1 fileSize1........................'+fileSize1);

update childObject;
}
}

//second method end

public static testmethod void testuplod(){
PageReference pageRef = Page.sub_FileUpload;
Account a=new Account();
a.name='Test';
insert a;
pageRef.getParameters().put('id',a.id);
pageRef.getParameters().put('ParentObjecName','Account');
pageRef.getParameters().put('ChildObjectName','tva__Account_documents__c');
pageRef.getParameters().put('ParentRefName','tva__Parent__c');
pageRef.getParameters().put('serverURL','https://na12.salesforce.com/services/Soap/c/12.0/00DU0000000Hg3A');
pageRef.getParameters().put('FILETYPEAPI','tva__file_type__c');
pageRef.getParameters().put('FILEDESCRIPTIONAPI','tva__file_description__c');
pageRef.getParameters().put('FILESIZEINBYTESAPI','tva__File_Size_in_Bytes__c');
pageRef.getParameters().put('FILENAMEAPI','tva__file_name__c');

sub_FileUploadController fp = new sub_FileUploadController();
Test.setCurrentPage(pageRef);
System.debug(fp.Policy);
System.debug(fp.getSignedPolicy());
System.debug(fp.getHexPolicy());
fp.page2onLoad();
fp.filesize=100000;
fp.page2onLoad();
}

}

---------------------------------------------------------------------------------------------------------------------------------------------------------

Hope i'll get a solution for this

Thanks in Advance

 

Navatar_DbSupNavatar_DbSup

Hi,

 

You can try below code

 

upload the pelase wait image  staticresorce with the name Load

 

//VF page

<apex:page showHeader="false" sidebar="false" controller="clsAttachFile">
<script>
//pop up code script START
function closediv()
{ 
   hide('pop1'); 
}

function showdiv()
{
   pop('pop1'); 
}

function hide(div)
{
    try
        {
            document.getElementById(div).style.display='none';
        }
    catch(ex)
    {
        hide('pop1');
        //alert(ex);
    }
}

function pop(div)
{
    try
    {
        document.getElementById(div).style.display='block';
    }
    catch(ex)
    {
        hide('pop1');
        //alert(ex);
    }
}

//pop up code script End

 




var Iddata = new Array();
var namedata = new Array();
var sizedata = new Array();
var Lastdata = new Array();

var Iddataold = new Array();
var namedataold = new Array();
var sizedataold = new Array();
var Lastdataold = new Array();

var count = 0;
var rowsdata;
var tdexistflag;
try
{
    var tabledata = window.parent.opener.document.getElementById("childtable");
    //alert(tabledata);
    var rows = tabledata.getElementsByTagName("tr");
    rowsdata = tabledata.getElementsByTagName("td");
    tdexistflag = true;
}
catch(e)
{
    //alert(e.message);
    tdexistflag = false;
}
function setdata()
{
       //alert(tdexistflag);
       if(tdexistflag == false)
       {
            //window.parent.opener.document.getElementById("idds").value= Iddata;
            var x ='<table id = "childtable" cellspacing="0" cellpadding="0" border="0" class="list"><tbody><tr class="headerRow"><th scope="col" class="actionColumn">Action</th><th class="" scope="col">File Name</th><th class="" scope="col">Size</th><th class="" scope="col">Last Modified</th></tr>';
            for(var k=0 ; k < Iddata.length; k++)
             {
               x =  x + '<tr onmouseover="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}" class="dataRow even last first"><td class="actionColumn"><a href="#" onclick="removeAttachment(\''+Iddata[k]+'\');">Remove</a></td><td class="dataCell" scope="row">'+namedata[k]+'</td><td class="dataCell">'+sizedata[k]+'</td><td class="dataCell">'+Lastdata[k]+'</td></tr>';
             }
            x =  x + '</tbody></table>';
            //alert(x);
           // window.parent.opener.document.getElementById("testdiv1").innerHTML = x;
         //  window.parent.opener.document.getElementById("idds").onchange();
         //   window.parent.close();
            return false;
       }
      else
      {
        // window.parent.opener.document.getElementById("idds").value= window.parent.opener.document.getElementById("idds").value+ "," +Iddata;
         var x ='<table id = "childtable" cellspacing="0" cellpadding="0" border="0" class="list"><tbody><tr class="headerRow"><th scope="col" class="actionColumn">Action</th><th class="" scope="col">File Name</th><th class="" scope="col">Size</th><th class="" scope="col">Last Modified</th></tr>';
         var h = 0;
         //alert(rowsdata.length);
         //alert(h);
         // alert(rowsdata[h].innerHTML);
         for(var j = 0; j<rowsdata.length/4; j++)
         {
             Iddataold[j] = rowsdata[h].innerHTML;
             h++;
             namedataold[j] = rowsdata[h].innerHTML;
             h++;
             sizedataold[j] = rowsdata[h].innerHTML;
             h++;
             Lastdataold[j] = rowsdata[h].innerHTML;
             h++;
         }
         for(var k=0 ; k < Iddataold.length; k++)
         {
             x =  x + '<tr onmouseover="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}" class="dataRow even last first"><td class="actionColumn">'+Iddataold[k]+'</td><td class=" dataCell  " scope="row">'+namedataold[k]+'</td><td class=" dataCell">'+sizedataold[k]+'</td><td class="dataCell">'+Lastdataold[k]+'</td></tr>';
         }
         for(var k=0 ; k < Iddata.length; k++)
         {
             x =  x + '<tr onmouseover="if (window.hiOn){hiOn(this);}" onmouseout="if (window.hiOff){hiOff(this);}" onfocus="if (window.hiOn){hiOn(this);}" onblur="if (window.hiOff){hiOff(this);}" class="dataRow even last first"><td class="actionColumn"><a href="#" onclick="removeAttachment(\''+Iddata[k]+'\');">Remove</a></td><td class=" dataCell  " scope="row">'+namedata[k]+'</td><td class=" dataCell">'+sizedata[k]+'</td><td class="dataCell">'+Lastdata[k]+'</td></tr>';
         }
         x =  x + '</tbody></table>';
      //   window.parent.opener.document.getElementById("testdiv1").innerHTML = x;
       //  window.parent.opener.document.getElementById("idds").onchange();  
      //   window.parent.close();
         return false;
      }
    
}
</script>

<style> 
    .parentDisable
    {
    z-index:1999;
    width:100%;
    height:100%;
    position:absolute;
    top:3px;
    display:none;
    left:0;
    opacity: 9.65;
    }
    .parentDisable2222
    {
    z-index:1999;
    width:300px;
    height:300px;
    position:absolute;
    top:30px;
    left:100px;
    //left:400px;
    right:600px;
    }
</style>

<apex:form >
<div class="genericPageBlockTable">
<table>
<tbody>
<tr>
        <td>
        <strong>1.</strong>
        </td>
        <td><strong>Select the File</strong></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>Type the path of the file or click the Browse button to find the file.</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td style="padding-bottom: 1em">
        <apex:inputFile title="Type the path of the file or click the Browse button to find the file." size="20" value="{!propbody}" fileName="{!propfilename}" id="photo" contentType="{!propcontenttype}" ></apex:inputFile>
    <div id="ErrorDiv" style=" display:none; color:red;" ><b>Error:</b> Please specify a file to upload. Type in the path to the file, or use the "Browse" button to locate it in your local file system.</div>
    </td>

    
</tr>
<tr>
    <td><strong>2.</strong></td>
    <td><strong>Click the "Attach File" button.</strong></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>Repeat steps 1 and 2 to attach multiple files.</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>( When the upload is complete the file information will appear below. )</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>        
        <apex:commandButton id="Upload" value="Attach File" action="{!upload}" onclick="showdiv();"/>   
    </td>
</tr>
</tbody>
</table>
</div>
</apex:form>
<apex:form >
<table class="fileUploadTableBottom">
<tbody>
<tr>
    <td><strong>3.</strong></td>
    <td><strong>Click the Done button to return to the previous page.</strong></td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>( This will cancel an in-progress upload. )</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>
        <apex:commandButton onclick="return setdata();" value="Done"/>        
    </td>
</tr>
</tbody>
</table>
<div id="defaultDiv" >
<table>
<apex:pageBlock tabStyle="Account"> 
<div id="head_1_ep" class="pbSubheader tertiaryPalette" style="background-color:#cfeef8;">
         <h3 style="color:black;">You have just uploaded the following file</h3>           

              <table width="100%" bgcolor="#FAFAFA">
                
               <apex:repeat id="docid" value="{!eventinfo}" var="docdata"> 
               <tr >
                  <td colspan="0"><b>File Name</b></td>
                  <td colspan="3"><b>{!docdata.name}</b></td>
               </tr>
               <tr >
                  <td colspan="0"><b>File Size</b></td>
                  <td colspan="3"><b>{!docdata.size}</b></td>
               </tr>
               <script>
                    Iddata[count] = "{!docdata.Id}";
                    namedata[count] = "{!docdata.name}"; 
                    var s="{!docdata.size}";                           
                            var sizedesc='bytes';
                            //alert(s);
                            if(s>1024)
                            {
                                s=(s/1024);
                                sizedesc='KB';
                            }
                            var finalsize = Math.round(s)+' '+sizedesc;
                  //  alert(finalsize);
                    sizedata[count] = finalsize; 
                    //alert('{!docdata.Lmodified}');
                       var attachmentdate=new Date('{!docdata.Lmodified}');
                    //var attachmentdate=("{!docdata.Lmodified}");
                    //alert(attachmentdate);
                            var hour=attachmentdate.getHours();
                            var ampm= "AM";;
                            if (hour>= 12) 
                            {
                                hour= hour-12;
                                ampm= "PM";
                            }
                            if (hour== 0) 
                            {
                                hour= 12;
                            }
                            //alert(attachmentdate.getMonth()+1);
                            var dateString =((attachmentdate.getMonth()<=0)?1:attachmentdate.getMonth()+1) + "/" + ((attachmentdate.getDate()<=0 )?1:attachmentdate.getDate())+ "/" + attachmentdate.getFullYear() + " "+hour+":"+attachmentdate.getMinutes()+" "+ampm;
                            //alert(dateString);
                    Lastdata[count] = dateString;
                    count++; 
                </script>
               </apex:repeat> 
               </table>    
</div>

                 
               
</apex:pageBlock>

</table>
</div>

<div id="pop1" class="parentDisable" style="left:15px;top:-18px;">
   <div id="smalldvImage" class="parentDisable2222" >   
   <table width="100%" align="center">
        <tr align="center"> 
            <td width="33%"></td>
            <td align="center"> 
                <img id="img201" height="300px" width="300px" align="center" src="{!URLFOR($Resource.Load)}"/>
            </td>
            <td width="33%"></td>
        </tr>
        <tr>
            <td colspan="3" align="center">
                    <!--<div style="background-color: #808080; color: #FFFFFF; font-weight: bold; font-size: medium;">-->
                    <div style="background-color:#FAFAFA; font-weight: bold; font-size: medium;">
                    Your request is being processed, it may take few seconds.
                    </div>
            </td>
        </tr>
    </table>    
    </div>
</div>




</apex:form>

<script>
document.getElementById("defaultDiv").style.display='none';
if({!errorflag})
{
     alert('Some Internal Error Occure plz... try again');
}
else if({!emptyflag})
{
     //alert('inner');
     document.getElementById("defaultDiv").style.display='none';     
     document.getElementById("ErrorDiv").style.display='block';
}
if({!check})
{
   //alert('true');
   document.getElementById("defaultDiv").style.display='none';
}
else
{
    //alert('false');
    document.getElementById("defaultDiv").style.display='block';
}
</script>
</apex:page>


// Controller

public class clsAttachFile
{
    public boolean errorflag{get;set;}
    public boolean emptyflag{get;set;}
    public boolean check{get;set;}
    
    public class eventuploaddata
    {
        public string id{get;set;}
        public string name{get;set;}
        public string size{get;set;}
        public DateTime Lmodified{get; set;}
    }
    public list<eventuploaddata> eventinfo{get;set;}
    public clsAttachFile()
    {
        eventinfo = new  list<eventuploaddata>();
        check =true;
    }     
    Public Transient blob propbody{get;set;}
    Public Transient string propfilename{get;set;}
    Public Transient string propcontenttype{get;set;}
   
    public void upload()
    {
       propfilename = ((propfilename == null || propfilename == '')?null:propfilename); 
       if(propfilename != null)
       {
           try
           {
                Document doc = new Document();
                doc.name = propfilename;
                doc.contenttype = propcontenttype;
                doc.body = propbody;
                doc.AuthorId = UserInfo.getUserId();
                LIST<FOLDER> fol = [SELECT ID,NAME FROM FOLDER WHERE NAME = 'Shared Documents' and type = 'document'];
                if(fol.size() > 0)
                doc.FolderId = fol[0].id;
                else
                doc.FolderId = UserInfo.getUserId();
                doc.IsPublic = true;
                insert doc;
                document doc1 = [select id,name,BodyLength,LastModifiedDate from document where id=: doc.id];
                eventuploaddata e= new eventuploaddata();
                e.id = doc1.id;
                e.name = doc1.name;
                //if(doc1.BodyLength >= 1024)
                e.size = String.valueof(doc1.BodyLength/1024);
                //else
                //e.size = String.valueof(doc1.BodyLength);
                e.Lmodified = (doc1.LastModifiedDate);
                eventinfo.add(e);
                check = eventinfo.isEmpty();
                system.debug('check'+check);
                emptyflag = false;
                errorflag = false;
           }
           catch(exception ex)
           {
                errorflag = true; 
           }
       } 
       else
       {
           emptyflag = true;
       }
    } 
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.