Jquery Ajax Simple File Upload
AJAX file upload tutorial. Home Tutorials AJAX basic tutorials. In this tutorial I will show you how to create simple AJAX file upload system using PHP and Java. Fighting Vipers 2 Zip. Script. Tutorial info Name AJAX file upload tutorial. Total steps 1. Category AJAX basic tutorials. Date 2. 00. 8 0. Level Normal. Product See complete product. Viewed 8. 91. 14. Bookmark AJAX file upload tutorial. Step 1 AJAX file upload. AJAX file upload tutorial. First of all I have to say that to create a pure AJAX file upload system is not possible because of security limitations of Java. Script. All of the Ajax upload systems I know use some third party toolpackage or only mimics the AJAX feeling. Even so it makes file upload process a bit nicer. In the next section I will present you a solution which imitates the AJAX process, but uses a normal upload process and i. Frames. The concept Create a simple HTML form for file upload. Set the target to an i. Frame which is on the actual page but not visible. TfVK73CUk8/hqdefault.jpg' alt='Jquery Ajax Simple File Upload' title='Jquery Ajax Simple File Upload' />Call a Java. Script function on form submit to display the animation. After the PHP part finishes the upload process, then it hides the animation. Creating the HTML file The HTML file we will use in this article is quite simple. It just have a simple form with a file field and a submit button. However dont forget about the enctype parameter. Code lt formactionupload. File lt inputnamemyfiletypefile lt inputtypesubmitnamesubmit. BtnvalueUpload lt form Besides this we need to add a bit more code to it. First we need a block where we will display the progress animation. We need an other block where we inform the visitor whether the upload was success or not. Besides this we need to add a hidden i. Frame to the page which is used as the form target. At least we add an on. Submit event to the form. So our HTML body looks like this Code lt pidf. Loading. lt br lt imgsrcloader. Upload File lt inputnamemyfiletypefile lt inputtypesubmitnamesubmit. Paul Williams Greatest Hits. BtnvalueUpload lt form lt iframeiduploadtargetnameuploadtargetsrcstylewidth 0 height 0 border 0px solid fff lt iframe lt body By default the progress animation block content is hidden. We need a Java. Script function which makes this block visible if the submit button was pressed. It is a very simple code, that only changes the visibility parameter. Code function start. Upload document. Element. By. Idf. Besides this we need an other function, what we will call at the end of the upload process. This code will be print out a result message depending on its parameter and hides the progress block again. Code function stop. Uploadsuccessvar result ifsuccess 1 document. Element. By. Idresult. HTML lt span classmsg The file was uploaded successfullylt span lt br lt br else document. Element. By. Idresult. HTML lt span classemsg There was an error during file uploadlt span lt br lt br document. Element. By. Idf. Before we creating the PHP code we still need to create a style for the form and the progress block. The form style is very simple, but the progress block style sets the z index, position and visibility parameter as well. Vista Las Islas Hotel Spa Costa Rica. Code f. 1uploadprocess z index 1. Now we can focus on the server side. Server side code The server side code is written in PHP and it is very short and simple. First we need to set the file destination path. In this case we will use the actual working directory. Afterwards we introduce a variable that shows if there was an error or not during the upload process. Next we move the uploaded file from the tmp directory to its defined location and set the result variable if upload was success. At the end I have inserted a sleep command to make animation a bit longer in case of very fast uploads. Now the end the PHP code looks like this Code lt DIRECTORYSEPARATOR result 0 targetpath destinationpath. FILESmyfilename result 1 Finish the work from i. Frame The output of the PHP code will be displayed executed inside the i. Frame. As you remember the i. Frame is not visible, however we can call a Java. Script function here. And exactly this is the point where we can call the Java. Script function defined in the HTML code to hide the progress animation and display the file upload result on the main page. We can do it with the following Java. Script code Code lt script languagejavascript typetextjavascript window. Uploadlt php echo result lt script Thats it. You can find a complete AJAX file upload system in the Products section. Tags ajax file upload tutorial, ajax file upload, file upload tutorial, ajax file, ajax upload. Awesome jQuery File Upload Plugins to upload files Ajax style. File upload plugins are easy to integrate to upload files to your forms or web pages. Jquery Ajax Simple File Upload' title='Jquery Ajax Simple File Upload' />You can with HTML5. NB The file data returned MUST be base64 encoded because you cannot JSON encode binary data. In my AJAX response I have a data structure that.
Comments are closed.