PHP Image Upload

This tutorials illustrates how to upload image using PHP

Step 1

Create a folder named "upload"

Step 2

Copy & paste the following codes-

<?php

if(isset($_POST['Submit']))
{
$current_image=$_FILES['image']['name'];
$extension = substr(strrchr($current_image, '.'), 1);
if (($extension!= "jpg") && ($extension != "jpeg"))
{
die('Unknown extension');
}
$time = date("fYhis");
$new_image = $time . "." . $extension;
$destination="uploads/".$new_image;
$action = copy($_FILES['image']['tmp_name'], $destination);
if (!$action)
{
die('File copy failed');
}else{
echo "File copy successful";
}
}else{

?>

<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="image" >
<input type="submit" name="Submit" value="Upload">
</form>

<?php

}

?>

Finally, save the file as "upload.php" and test. That's it!