Tuesday, January 19, 2010

How to upload file in php

Step 1 - Save Bellow code name "upload.php"
Step 2 - Create a folder name upload for file upload
Note : Remove "\" from all HTML tag and php start tag

<\?php
        if(isset($_REQUEST['submit']))
        {
            $tmp_file = $_FILES['upload']['tmp_name'];
            $filename = $_FILES['upload']['name'];
           
            if(move_uploaded_file("$tmp_file", "upload/$filename"))
            {
                echo "File Success Fully Uploaded";
            }
            else
            {
                echo "File Upload Failed";
            }
        }
?>
<\html>
<\body>
<\form name="frm" method="post" action="upload.php" enctype="multipart/form-data">
    <\input type="file" name="upload">
    <\input type="submit" name="submit" value="Upload">
<\/form>
<\/body>
<\/html>

No comments: