Javascript HTML5 File Upload FileReader API, html5filereader
The file upload function is becoming more and more common. All social websites, media websites, such as Youku videos and Weibo, provide functions such as uploading images and uploading videos. However, in the past, WEB programmers knew that it was very troublesome to upload files using HTML forms. In pa
This program is the use of 3.x Firefox browser can read the characteristics of local files, to achieve through the XMLHttpRequest upload large file features, and in the process can upload dynamic display upload progress. Slightly modified, and with the server side, you can achieve the extension of breakpoints and many other functions.This example is mainly to study the characteristics of Firefox
I. Core functions: FileSystemObject objects. To implement file operations in Javascript, FileSystemObject objects are primarily used.
Ii. FileSystemObject programming Trilogy
(1) create a FileSystemObject object, application-related methods, and Access Object-related attributes.VaR FSO = new activexobject ("scripting. FileSystemObject ");(2) Use the createtextfile method to create a text file:VaR F1 = FSO.
"functions" is the array of functions that exist in this JavaScript file.As you can see, the code to pull and execute a script is straightforward. the browser first downloads, and then interprets the JavaScript file. if you 've read any other articles on AJAX development, you might remember that in most cases the thir
, which is set to point to an IFRAME on the current page. This is critical by setting the target property so that the form's submitted page appears in the IFRAME, avoiding the current page jump. Because we still have to show the progress bar on the current page.
#progress This div is used to display the progress bar.
Be careful not to forget to add session_start () at the beginning of the index.php.
Process uploaded files
The action of the form points to upload.php, where we process the uplo
In the previous article, I introduced the JavaScript operations file, focusing on how to get the Files object. These objects contain the metadata of the files that can be obtained when uploading or dropping them into a browser. With the file, of course, the next step is to read the file.FileReaderFileReaderThe function
in read-only mode. This file cannot be written. ForWriting 2 open the file in write mode ForAppending 8 open the file and write from the end of the file. The format parameter can be any of the following settings: value description TristateTrue open a
session_start () at the beginning of index. php ().
Process uploaded filesThe action of the form points to upload. php. we process the uploaded file in upload. php and store it to the current directory. This is no different from normal Upload processing.
If (is_uploaded_file ($ _ FILES ['file1'] ['tmp _ name']) {Move_uploaded_file ($ _ FILES ['file1'] ['tmp _ name'], "./{$ _ FILES ['file1'] ['name']}");}?> Ajax get progress informationThis step is cr
file object also has a webkitslice () or Mozslice () method for generating a Blob object. This object can be read filereader like a file object. These 2 methods receive 3 parameters: The 1th argument is the starting position, the 2nd is the ending position, the end of the file is omitted, and the 3rd is the content ty
.# The div SS div is used to display the progress bar.Remember to add session_start () at the beginning of index. php ().Process uploaded filesThe action of the form points to upload. php. We process the uploaded file in upload. php and store it to the current directory. This is no different from normal Upload processing. The code is as follows:Copy code If (is_uploaded_file ($ _ FILES ['file1'] ['tmp _ name']) {Move_uploaded_file
. There is no difference between the upload processing and the usual situation.
if (Is_uploaded_file ($_files[' file1 ' [' tmp_name '])) {Move_uploaded_file ($_files[' file1 ' [' Tmp_name '], "./{$_files[' file1 ' [' Name ']}");}? >ajax Get Progress InformationThis step is the key, we need to create a progress.php file to read the progress information in the session; We then add
JavaScript uses FileSystemObject object to write the content of a text file. filesystemobject
This example describes how to use a FileSystemObject object to write text files in JavaScript. Share it with you for your reference. The details are as follows:
This code is mainly used to practice the JavaScript FileSystemObj
submitted is displayed in iframe to avoid the current page jump. Because we have to display the progress bar on the current page.
# Progress p is used to display the progress bar.
Remember to add session_start () at the beginning of index. php ().
Process uploaded files
The action of the form points to upload. php. we process the uploaded file in upload. php and store it to the current directory. This is no different from normal Upload processing.
T
For the file download, can be said to be a very common topic, the front-end of many projects will have such a demand, such as the export of Highchart charts, online picture editing in the image preservation, online code editing code export and so on. And many times, we only give a link, the user needs to right click on the link, and then choose "Save as", this process is not troublesome, but still need two steps, if the user want to save the page of m
:
CopyFolder (object directory, target directory, overwrite)//Copy object directory to target directory, when overridden to true, if target directory exists will overwrite file
Copy Code code as follows:
CreateFolder (directory name)//Create a new directory
Copy Code code as follows:
CreateTextFile (filename, overwrite)//Create a new file, if
In the early stage, system operations were performed under. net, and the implementation of the same functions was very complicated. I didn't expect javascript to be so simple, so I searched the code online and improved it.
Function PathList (path ){
Var fso = new ActiveXObject ("Scripting. FileSystemObject ");
Var fldr = fso. GetFolder (path );
Var fd = new Enumerator (fldr. SubFolders );
For (;! Fd. atEnd (); fd. moveNext ()){
Sd = fd. item ();
WScri
Early in the. NET for system operations, the same function to achieve a very complex, did not expect to use JavaScript is so simple, so search the Web code and improve.
function PathList (path) {
var fso = new ActiveXObject ("Scripting.FileSystemObject");
var Fldr = fso. GetFolder (path);
var fd = new Enumerator (Fldr. subfolders);
for (;!fd.atend (); Fd.movenext ()) {
SD = Fd.item ();
WScript.Echo (Sd.path);
Write to
the File API.
By listening to the change event, we can learn about the files that the user chooses, and add a Files collection that contains the file object, each of which corresponds to one. And all have the following read-only property name,size,type,lastmodifieddate.
Take the for example, monitor the onchange to print its
scripts are all written in JavaScript. To Write Excellent Greasemonkey applications, you must be familiar with JavaScript programming, understand JavaScript DOM programming, and analyze the HTML code structure. If you want to learn more about Greasemonkey, read Greasemonkey. Below I will publish the script code for th
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.