'/DOC_REPOSITORY_FOLDER_PATH/samplefile.docx'; $tmp_filename = $_FILES['content']['tmp_name']; $upload_status = move_uploaded_file($tmp_filename, $filepath); ?>
$_FILES['content']['tmp_name'] - $_FILES array is where PHP stores all the information about files. There are two elements of this array - content and tmp_name content - document content that is uploaded to Zoho editors while doing a HTTP multi-part form POST. tmp_name - tmp_name contains the path to the temporary file that resides on the Zoho document server. move_uploaded_file - Thisfunction moves the temporary file from Zoho's document server to the document repository folder path that you provide along with the file name and file extension. Note: Example of doc repository folder path - "/apache/htdocs/zohosave/samplefile.docx" or "C:\Zylker\Documents\samplefile.docx"
package com.Sample; import java.lang.*; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.ServletException;import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; //add this jar - commons-fileupload-1.3.3.jarimport org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; public classSaveUrlServletextendsHttpServlet { private static final long serialVersionUID = 1L; private static finalString UPLOAD_DIRECTORY = "upload"; private static final int MEMORY_THRESHOLD = 1024 * 1024 * 3; // 3MBprivate static final int MAX_FILE_SIZE = 1024 * 1024 * 40; // 40MBprivate static final int MAX_REQUEST_SIZE = 1024 * 1024 * 50; // 50MBpublic void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { PrintWriter writer = response.getWriter(); if (!ServletFileUpload.isMultipartContent(request)) { writer.write("RESPONSE: Form must has enctype=multipart/form-data."); response.setStatus(response.SC_BAD_REQUEST); writer.flush(); return; } DiskFileItemFactory factory = newDiskFileItemFactory(); factory.setSizeThreshold(MEMORY_THRESHOLD); factory.setRepository(newFile(System.getProperty("java.io.tmpdir"))); ServletFileUpload upload = newServletFileUpload(factory); upload.setFileSizeMax(MAX_FILE_SIZE); upload.setSizeMax(MAX_REQUEST_SIZE); String uploadPath = getServletContext().getRealPath("")+ File.separator + UPLOAD_DIRECTORY; File uploadDir = newFile(uploadPath); if (!uploadDir.exists()) { uploadDir.mkdir(); } try { List formItems = upload.parseRequest(request); System.out.println("Form Items Values >>> "+formItems); if (formItems != null && formItems.size() > 0) { for (FileItem item : formItems) { System.out.println("Field Name:"+item.getFieldName()); if(!item.isFormField()){ if (item.getFieldName().equalsIgnoreCase("content")){ String fileName = newFile(item.getName()).getName(); String filePath = uploadPath + "/" + fileName; File storeFile = newFile(filePath); item.write(storeFile); } }else{ byte[] fieldVal; if (item.getFieldName().equalsIgnoreCase("filename")){ fieldVal = item.get(); String fileNameValue = newString(fieldVal); System.out.println(item.getFieldName()+" value: "+fileNameValue); }else if(item.getFieldName().equalsIgnoreCase("id")){ fieldVal = item.get(); String idValue = newString(fieldVal); System.out.println(item.getFieldName()+" value: "+idValue); } else if(item.getFieldName().equalsIgnoreCase("format")){ fieldVal = item.get(); String formatValue = newString(fieldVal); System.out.println(item.getFieldName()+" value: "+formatValue); } } } response.setStatus(response.SC_OK); writer.write("Document Saved Successfully!"); } }catch (Exception ex) { response.setStatus(response.SC_BAD_REQUEST); writer.write("RESPONSE:Document save fails"); // For Custom message showing in Zoho editor } } public void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException { PrintWriter writer = response.getWriter(); writer.write("Not Allowed"); response.setStatus(response.SC_BAD_REQUEST); } }
'this is page load event Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load' declaring variable - object declared to get the content of uploaded file Dim m_objFile As HttpPostedFileDim filename As String'here we are getting the requested file content m_objFile = Request.Files("content")' Here we are getting the exact file name that was sent during HTTP POST form submit filename = Request.QueryString("filename") 'saving the file in document repository folder path Request.Files("content").SaveAs("C:\inetpub\" + filename) End Sub Note: Any text inside the sample code preceded by single quotes (') is a comment in ASP.Net.
Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.
If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.
Write to us: support@zohoforms.com
Quick Links |
Workflow Automation |
Data Collection |
|
||
Form Templates |
||
|
||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|