Making Upload File Script Using Php html and java script with validation
<pre><!DOCTYPE html>
<head>
</head>
<body></pre> //use pre tag to not show these tags in server
<center>
< form action = " upload.php" method = " post " enctype = " multipart / form-data "
name = " upload " >
< table width =" 200 " border = " 2 " cellspacing = " 2 " cellpadding = " 2 " >
< tr >
< td > Upload a file< /td >
< td > < input name = " file " type = " file " / > < / td >
< / tr >
< tr >
< td colspan = " 2 " > < center >
< input name = " sub " type = " submit " value = " upload " />
< / center >< / td >
</tr>
</table>
</form>
</center>
</body>
</html>
<?php
error_reporting(0);
if(isset($_POST['sub']))
{
$name=$_FILES['file']['name'];
$type=$_FILES['file']['type'];
$size=$_FILES['file']['size'];
$tmp=$_FILES['file']['tmp_name'];
if($name=='')
{
echo"<script>alert('upload file')</script>";
exit();
}
if(( $type == "image/jpeg" )||($type=="image/gif")||($type=="image/png"))
{
if($size<=500000)
{
if (file_exists("upload file" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
exit();
}
move_uploaded_file($tmp,"$name");
echo"<center> <font color='pink' ><h2>successfully uploaded</h2></font><br>".""."<img src=$name> </center>";
}
else
{
echo"more size";
}
}
else
{
echo"type not support";
}
}
?>
For more php tutorial PHP-tutorial
Output
No comments:
Post a Comment