how to upload an image using php and javascript.i can upload multiple images .

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gramya
    New Member
    • Jul 2007
    • 2

    how to upload an image using php and javascript.i can upload multiple images .

    hello,
    i got a code in google search which can upload images using php and javascript (iframes).I am trying to modify the code so that only one image which is browsed currently should be displayed. but i didnot suceed.please help me.
    thanking you,
    ramya
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, ramya. Welcome to TSDN!

    What do you want your code to do? Give an example.
    What is your code doing that you don't want it to do? Give an example.
    What is your code *not* doing that it is supposed to? Give an example.

    Comment

    • gramya
      New Member
      • Jul 2007
      • 2

      #3
      I must upload a image . I have a code which is written in php and javascript. It is working sucessfully.But the is appending the image which i am browsing to the current page. But my requirement is to replace the previous image with the currently browsed image. the code is given below. So please help me.
      thankyou for your reply.

      <?php
      $ftmp = $_FILES['image']['tmp_name'];
      $oname = $_FILES['image']['name'];
      $fname = 'upload/'.$_FILES['image']['name'];
      if(move_uploade d_file($ftmp, $fname)){
      ?>
      <html><head><sc ript>
      var par = window.parent.d ocument;
      var images = par.getElementB yId('images');
      var imgdiv = images.getEleme ntsByTagName('d iv')[<?=(int)$_POS T['imgnum']?>];
      var image = imgdiv.getEleme ntsByTagName('i mg')[0];
      imgdiv.removeCh ild(image);
      var image_new = par.createEleme nt('img');
      image_new.src = 'resize.php?pic =<?=$oname?>';
      image_new.class Name = 'loaded';
      imgdiv.appendCh ild(image_new);
      </script></head>
      </html>
      <?php
      exit();
      }
      ?><html><head>
      <script language="javas cript">
      function upload(){
      // hide old iframe
      var par = window.parent.d ocument;
      var num = par.getElements ByTagName('ifra me').length - 1;
      var iframe = par.getElements ByTagName('ifra me')[num];
      iframe.classNam e = 'hidden';

      // create new iframe
      var new_iframe = par.createEleme nt('iframe');
      new_iframe.src = 'upload.php';
      new_iframe.fram eBorder = '0';
      par.getElementB yId('iframe').a ppendChild(new_ iframe);

      // add image progress
      var images = par.getElementB yId('images');
      var new_div = par.createEleme nt('div');
      var new_img = par.createEleme nt('img');
      new_img.src = 'indicator.gif' ;
      new_img.classNa me = 'load';
      new_div.appendC hild(new_img);
      images.appendCh ild(new_div);

      // send
      var imgnum = images.getEleme ntsByTagName('d iv').length - 1;
      document.iform. imgnum.value = imgnum;
      setTimeout(docu ment.iform.subm it(),5000);
      }
      </script>
      <style>
      #file {
      width: 350px;
      }
      </style>
      <head><body><ce nter>
      <form name="iform" action="" method="post" enctype="multip art/form-data">
      <input id="file" type="file" name="image" onchange="uploa d()" />
      <input type="hidden" name="imgnum" />
      </form>
      </center></html>

      Comment

      Working...