Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to upload file in PHP

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 210
    Comment on it
    <!DOCTYPE html>
    <html>
        <head>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        </head>
        <body>
            <form action="upload.php" method="POST" enctype="multipart/form-data">
                <table cellpadding="10">
                    <tr>
                        <td>Name : </td>
                        <td><input type="text" name="name" /></td>
                    </tr>
                    <tr>
                        <td>Photo : </td>
                        <td><input type="file" name="photo" /></td>
                    </tr>                
                    <tr>
                        <td align="center" colspan="2">
                            <input type="submit" value="Upload Data" />
                        </td>
                    </tr>                
                </table>            
            </form>
        </body>
    </html>
    </br>
    <?php
        $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';      
        $str = str&#95;shuffle($str);         
        $photo = substr($str, 1,15);
        $name = $&#95;POST['name'];
        $filename = $&#95;FILES['photo']['name'];
        $x = strpos($filename, '.');
        $extname = substr($filename, $x);
        $filesize = $&#95;FILES['photo']['size'];
        $filetype = $&#95;FILES['photo']['type'];
        $tmp&#95;name = $&#95;FILES['photo']['tmp&#95;name'];
        move&#95;uploaded&#95;file($tmp&#95;name, 'uploads/'.$photo.$extname);
    
    ?>
    <!DOCTYPE html>
    <html>
        <head>
            <title></title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        </head>
        <body>
            Name : <?php echo $name;?>
            <hr>
            File Name : <?php echo $filename;?>
            <hr>
            Size : <?php echo $filesize;?> Bytes
            <hr>
            Type : <?php echo $filetype;?>
            <hr>
            Temp Name : <?php echo $tmp&#95;name;?>
        </body>
    </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: