Tuesday, April 16, 2013

uploading the images and videos


upload form

<html>
<body>
<form action="uploads.php" method="post" enctype="multipart/form-data">
<label for="file">File Name </label>
<input type="text">
<input type="file" name="file" id="file"> <br>
<input type="submit" value="send" name="submit">
</form>
</body>
</html>

uploading code


<?php
$tmp=$_FILES["file"]["tmp_name"];
$name=$_FILES["file"]["name"];
$size=$_FILES["file"]["size"];
$type=$_FILES["file"]["type"];
$error=$_FILES["file"]["error"];
$allowedext=array("jpg","jpeg","png","gif");
$extenstions=end(explode(".",$type));
if(($type == "image/jpg") || ($type == "image/jpeg") || ($type == "image/png") || ($type == "image/gif") || ($type == "image/fdf") &&  ($size<20000) && in_array($extenstions, $allowedext))
{
if ($error>0)
{
echo "Error :".$error;
}else
{
echo $tmp."location of file"."<br>";
echo $name."name of file"."<br>";
echo $size."file size"."<br>";
echo $type."file type"."<br>";
if(is_uploaded_file($name))
{
echo $name;
}else{
if(move_uploaded_file($tmp, "myupload/$name"))
{
echo "file is moved";
}else
{
echo "file is not moved";
}
}
}
}else
{
echo "invalid";
}
?>
<a href="uploadform.php">Back To Upload Form</a>

No comments:

Post a Comment