How to copy the file from one folder to another using js
i am facing the problem in coping the images from one folder to ano开发者_开发问答ther . It is possible through JS means please guide me, i had the image path (eg : C:\Program Files\xampp\htdocs\gallary\images\addnew.gif
) just i want to copy the images to another folder using js .thanks in advance.
You cannot use javascript to do this within the web browser. Javascript can only execute code in the browser of the person viewing the web page, not on the web server. Even then, javascript is "sandboxed" for security so it cannot access the users files, etc. Imagine the privacy problems if every webpage you visited had access to your My Documents folder!
PHP, however, can do this on the web server (I assume you have PHP instaled because you have XAMPP
in the path to your image). The relevant PHP function is copy
:
bool copy ( string $source , string $dest [, resource $context ] )
In your case, you probably want to call it like this:
success = copy('C:\\Program Files\\xampp\\htdocs\\gallary\\images\\addnew.gif', 'C:\\images\\addnew.gif')
if (!success){
echo "Could not copy!"
}
The simplest way to trigger this file copy is when a PHP web page is loaded. However, if you want to trigger this file-copy via javascript, you might want to look into using an AJAX style technique, where a javascript event sends an HTTP request to your web-server in the background. The web-server can then do the file copy in PHP. If you do take this approach, I would recommend that you:
- Use a javascript API like jQuery which has built in functions to make this easier.
- Be very very careful about security. You don't want someone snooping around on your website to be able to delete or copy arbitrary files.
You could use MS JScript http://msdn.microsoft.com/en-us/library/e1wf9e7w(VS.85).aspx
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile ("c:\\mydocuments\\letters\\*.doc", "c:\\tempfolder\\")
this can't be done from a browser, but you can run it in windows (using the windows script host) directly. You could also do it with node.js (server side javascript) which would be a more cross platform way. If you're trying to do it from in the browser on the client side it is not possible from any language for obvious security reasons.
精彩评论