开发者

creating folders using jquery

开发者 https://www.devze.com 2023-03-04 19:11 出处:网络
I\'m downloading files using the below code. Can I create folders dynamically and download files to each folder for each category of requiredKeyWords

I'm downloading files using the below code. Can I create folders dynamically and download files to each folder for each category of requiredKeyWords

$.each(requiredCities,function(keya,v开发者_运维百科alb){
        $.each(requiredKeyWords,function(keyc,vald){
            var timerId = setInterval(function(){
            download(...);
            clearInterval(timerId);
            }, 4000*(i++));    
        });
    });
});

function download(url){
    ...
}

thank you


No. JavaScript is sandboxed within the browser, giving you no access to the user's machine.

Really, it's for the best: Imagine every Joe and Jill can automagically create, move, read and alter things on your computer. That'd be a gianormous security hazard.


You can do a request using jQuery (like ajax() or post() methods) and get a HttpResponse with the file content and the desired headers. Obviously you'll need a server-side technology (ASP.NET, Java, PHP etc.) to receive the HttpRequest and return the HttpResponse.

Then, your browser will intercept this response as a download.

Also, you can simple redirect the URL to the file, whithout manual post, like pointed on this thred: Download File Using jQuery. In this case, the browser will do the request for you, read the response and interpret as a download.

But you cannot specifies where the user will choose to save the file (nor the name). Also, the user always can cancel any download. And finally, the browser's security can be configurated to deny downloads.

Finally is important to remeber that the browser will show a download window per time. Then, you cannot start 10 downloads at the same time. Do you use Gmail? As you can see there, when a user wants to download all attachments at the same time, Gmail creates a ZIP with all files inside and sends the download of that ZIP. This is the better automatized way to do it, but also don't is what you desire.


Fortunately, no. When running in a web browser, javascript has no access to the file system. That would be a massive security hole. The only way you can do that is using an ActiveX control, or a Java applet. Both options are evil.


It's possible in IE using ActiveX but not in other browsers.

http://www.codeproject.com/KB/scripting/JavaScript__File_Handling.aspx

"There are a few things to note before implementing FileSystemObject. Since its an ActiveX object it will not be created if the security level on the client machine is high. So the website have to be added to the trusted site list so that the ActiveX object can be created.

The user must have write access in the path specified while creating a file. In cases where there is uncertainty its better to write the file onto Temporary Folder of the system. The path for the Temp folder can be found using"

0

精彩评论

暂无评论...
验证码 换一张
取 消