How to upload a file using HTTP (without using FTP) ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kprawin
    New Member
    • Dec 2009
    • 5

    How to upload a file using HTTP (without using FTP) ?

    Hai everybody,
    Im trying to upload an image using a form by using POST method and another PHP file to receive and upload the file. I used the following lines of code and it shows some error and probably wrong output too.

    Code:
    //index.php
    <html>
    <body>
    
    <script language="javascript">
      function preview()
      {
      document.STUDENT_PHOTO.src=document.myform.myimage.value;
      }
      </script>
      
    <form name="myform" method="POST" enctype="multipart/form-data" action="disp.php">
    <img src="" alt="Click browse and locate the image." name="STUDENT_PHOTO" ID="STUDENT_PHOTO" height="170" width="170"/><BR />
    <input type="file" name="myimage" onchange="preview()" />
    <input type="submit">
    </form>
    </body>
    </html>
    
    
    //disp.php
    <?PHP
    
    if(ISSET($_POST['myimage'])) 
    { 
    $student_photo=$name.$_FILES['myimage']['name'];
    //copy($_FILES['myimage']['tmp_name'],".\\images\\".$student_photo);
    echo $student_photo;
    }
    else
    {
    echo "No image found";
    }
    
    ?>
    It prints "No image found". It shows the same even if I use $_REQUEST['myimage'].

    It prints "myimage" as undefined index and "name" as undefined variable if I use $_GET['myimage'].

    (I have changed the form method type as GET, POST in index.php for the above test cases and got the above output)

    Anybody pls help me.
    Advanced Thanks...
    Attached Files
    Last edited by Atli; Feb 25 '10, 05:19 AM. Reason: Added [code] tags.
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    You will get thousands of solutions if you look at google

    link. This was the first link that i got in search

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      You use the $_FILES array to read files, not the $_POST array.

      Look at the difference between how you read the image file in line #24 vs line #26. - You got it right in line #26.

      Comment

      Working...