Link to home
Start Free TrialLog in
Avatar of naeembhatti
naeembhattiFlag for United States of America

asked on

how can i save my images through javascript into my selected directory?

sir i have code this---

<body>
<img src="images/www.bikao.com/2.gif" />
<script language="javascript">
javascript:Ai7Mg6P='';
      for (i7M1bQz=0;i7M1bQz<document.images.length;i7M1bQz++){
                  Ai7Mg6P+='<img src='+document.images[i7M1bQz].src+'><br>';
                  images = document.images[i7M1bQz].src;//mine
            };
            if(Ai7Mg6P!=''){
                  //document.write('<center>'+Ai7Mg6P+'</center>');
            alert(images);//save all images here in 'images directory'
                  void(document.close());
            }else{
                  alert('No images!');
            }
</script>

</body>

i want to save all images in images directory where i am doing alert how can it would be done plz plz help me today is the dead line of the project just i have to save them all.

thanks in advance.
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Hello naeembhatti,

Unless it is a .hta application I doubt that browser will allow this... Anyway here is a small sample(s)
[JScript]
fso = new ActiveXObject("Scripting.FileSystemObject");
fso.CopyFile ("c:\\mydocuments\\letters\\*.doc", "c:\\tempfolder\\")
[VBScript]
FileSystemObject.CopyFile "c:\mydocuments\letters\*.doc", "c:\tempfolder\"


HTH

I
Avatar of naeembhatti

ASKER

sir i have modify my code like this

fso = new ActiveXObject("Scripting.FileSystemObject");
javascript:Ai7Mg6P='';
      for (i7M1bQz=0;i7M1bQz<document.images.length;i7M1bQz++){
                  Ai7Mg6P+='<img src='+document.images[i7M1bQz].src+'><br>';
                  images = document.images[i7M1bQz].src;//mine
            };
            if(Ai7Mg6P!=''){
            
                  //document.write('<center>'+Ai7Mg6P+'</center>');                  
                  //alert(Ai7Mg6P+'-'+images);                  
                  fso.CopyFile (images, 'images/'+images);
            //alert(images);

                  void(document.close());
            }else{
                  alert('No images!');
            }

i know it would not run on every browser but i when i run it on firefox it does not copy my image and if i run on ie(but not my requirement for ie) it gives my error "automation server can't create object"

??

ASKER CERTIFIED SOLUTION
Avatar of Ivo Stoykov
Ivo Stoykov
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
okey right i got it but e.g
if i have a singel file named as images.html
and code is simple this
<script type="text/javascript">
   
var fso = new ActiveXObject("Scripting.FileSystemObject");

fso.CopyFile("E:\AppServ_5\www\pligg\test\9.gif", "E:\AppServ_5\www\pligg\test\images/9.gif");

</script>

why this code is not running this is not .hta ?
or what could be other methods or example to copy file through javascript plz plz help me.
Avatar of KennyTM
KennyTM

Hi.

How about

<HTML>
<HEAD>
  <TITLE>HTA Demo</TITLE>
    <HTA:APPLICATION ID="oHTA"
     APPLICATIONNAME="myApp"
     BORDER="thin"
     BORDERSTYLE="normal"
     CAPTION="yes"
     ICON=""
     MAXIMIZEBUTTON="yes"
     MINIMIZEBUTTON="yes"
     SHOWINTASKBAR="no"
     SINGLEINSTANCE="no"
     SYSMENU="yes"
     VERSION="1.0"
     WINDOWSTATE="maximize"/>
  <SCRIPT>
function window.onload () {
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  fso.CopyFile("E:\\AppServ_5\\www\\pligg\\test\\9.gif", "E:\\AppServ_5\\www\\pligg\\test\\images\\9.gif");
}
</SCRIPT>
</HEAD>
<BODY><P>File copied.</P></BODY>
</HTML>

? The script is partly refered to http://msdn.microsoft.com/workshop/author/hta/reference/objects/hta.asp . Also look out for backslashes in Javascript: it's an escape character, and to say a normal "\" you'll need two: "\\".

I haven't tested the above script.
hmm no it is not copying the image.
ok let me think some other alternates for it.