Posted by: Sourav | May 18, 2011

A basic uploader using php


upload.html

<html>
    <head>
        <title>
            My first upload page
        </title>
        <body bgcolor=”black” >
           
           
            <div align=”center”>
              
         <form  enctype=”multipart/form-data” action=”uploader.php” method=”post”>
            <font color=”green”>
            Choose a file to upload:<br />
            <input name=”file4upload” type=”file”>
            <br /><br />
                <input  type=”submit” name=”submit” value=”Upload file” ></input>
   
         </form>
       
                </font>
            </div>
           
           
           
        </body>
</html>

uploader.php

<?php

$target_path=”uploads/”;
$target_path=$target_path.basename($_FILES[‘file4upload’][‘name’]);
if(move_uploaded_file($_FILES[‘file4upload’][‘tmp_name’],
                      $target_path))
{
   
    echo “The File “.basename($_FILES[‘file4upload’][‘name’]).” has been uploaded successfully”;

   
}
else
{
   
    echo ‘Please try again’;
}

?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: