2. Copying the same file to many locations on a network .

 

back to examples

 

The following code copies a students uploaded file to certain lecturers own personal hard disk drives. All MIME types are being allowed and blank file fields are not. Note the use of windows™ specific network paths and the check to see that each lecturer has an available directory for the student. An ordinary text field parameter is uploaded with the request which is the name of the student (it is assumed in this example that the name sent will always be a valid name).

 

 

 

XloadManager xman = new XloadManager(request);

 

 

xman.target("file1", "uploaded");

xman.upload();

 

StringBuffer error = new StringBuffer(100);

XloadFileUpload upload = (XloadFileUpload)xman.getFileUpload("file1");

if(upload.isAnUploadFailure()){

error.append("Your file failed to upload due to:" +

//list possible reasons or give generic

//message.

\n");

}else{

XloadFile file = upload.getFile("uploaded");

String name = xman.getParameter("studentName");

String[] lectCompNames = new String[12];

...

//populate the lectCompNames object with lecturers computer names

//from some other source.

...

String path = null;

for(int i = 0; i < lectCompNames.length; i++){

path = ("\\\\" + lectCompNames[i] + "\\students\\" + name);

XloadDirectory dir = xman.getDirectory(path);

if(dir != null)file.copyTo(dir);

}

}

 

//return a response using the error object if needed.

 

 

 

 

 

 

 

 

© Gubutech(Xload) 2006  (v1.2)