2 Replies Latest reply on Aug 13, 2006 2:50 PM by Soc4me3

    Upload image

    Soc4me3
      Hi,
      I have been working on a members area and wanted to have the users upload an image or avatar. I'm not sure how to upload the image to my php database. I use phpmyadmin. Below is the code for the picture. Can anyone help me?

      <script type="text/javascript">
      <!-- Begin
      // width to resize large images to
      var maxWidth=100;
      // height to resize large images to
      var maxHeight=100;
      // valid file types
      var fileTypes=["bmp","gif","png","jpg","jpeg"];
      // the id of the preview image tag
      var outImage="previewField";
      // what to display when the image is not valid
      var defaultPic="spacer.gif";
      function preview(what){
      var source=what.value;
      var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
      for (var i=0; i<fileTypes.length; i++) if (fileTypes ==ext) break;
      globalPic=new Image();
      if (i<fileTypes.length) globalPic.src=source;
      else {
      globalPic.src=defaultPic;
      alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
      }
      setTimeout("applyChanges()",200);
      }
      var globalPic;
      function applyChanges(){
      var field=document.getElementById(outImage);
      var x=parseInt(globalPic.width);
      var y=parseInt(globalPic.height);
      if (x>maxWidth) {
      y*=maxWidth/x;
      x=maxWidth;
      }
      if (y>maxHeight) {
      x*=maxHeight/y;
      y=maxHeight;
      }
      field.style.display=(x<1 || y<1)?"none":"";
      field.src=globalPic.src;
      field.width=x;
      field.height=y;
      }
      // End -->
      </script>
      </head>
      <body>
      <input name="photo" type="file" id="picField" onchange="preview(this)">
      <br>
      <img src="../spacer.gif" alt="Graphic will preview here" name="previewField" id="previewField">
        • 1. Re: Upload image
          NetZed Level 1
          Have you tried some of the free 'account' and 'members area' templates that come free with everything so you just have to change the code for the usernames and passwords. Do a search in google for some. But if you want to make your own I don't know I am not a very good designer. Try smallpark.org he is quite a good designer. A canadian student.
          • 2. Re: Upload image
            Soc4me3 Level 1
            thanks but yes i am trying to accomplish it using the code I have. Anyone else?