<form name= "Form_upload" method= "post" action= "<? echo htmlspecialchars ($_server[' php_self ');? > "enctype=" Multipart/form-data ">
<p><label><b> Uploading Files </b></label><input type= "file" name= "file" ></p>
<input type= "Submit" name= "Submit" value= "OK" >
</form>
<?php
if ($_post[' Submit ']== "OK")
{
if (($_files[' file ' [' Type ']== "Image/png") | | ($_files[' file '] [' type ']== "Image/png") | | ($_files[' file '] [' type ']== "Image/png") && ($_files[' file ' [' Size ']<500000)]
)
{
if ($_files["file" ["Error"]>0)
{
echo "Error code:". $_files[' file ' [' Error '];
}
Else
{
echo "Upload:". $_files[' file ' [' Name '];echo ' <br/> ';
echo "type:". $_files[' file ' [' Type '];echo ' <br/> ';
echo "Size:". $_files[' file ' [' Size ']/1024;echo "kb<br/>";
echo "tmp file:". $_files[' file ' [' Name '];echo "<br/>";
echo "File name:". $_files[' file ' [' Name '];
if (file_exists ("Uplaod/hadoop.png"))
{
echo $_files[' file ' [' Name ']. " has already exists! ";
}
Else
{
if (move_uploaded_file ($_files[' file '] [' tmp_name '], "upload/". $_files[' file ' [' name ']))
{
echo "Stored in:upload/". $_files[' file ' [' Name '];
}
Else
{
echo "Upload failed!";
}
}
}
}//type
Else
{
echo "Invalid file! file type or size does not match! ";
}
}
?>
PHP File Upload Code