Di bawah ini adalah script pada halaman html untuk membuat form memasukan data.
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form action ="upload_file.php" metode="post" enctype="multipart/form-data">
<label for="file"> Filename: </label>
<input type="file" name="file" id="file" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
script php untuk mengupload file image yg dibatasi pada format jpg, png, gif.
<?php
if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png"))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
}
}
else
{
echo "Invalid file";
}
?>
<?php
if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png"))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
}
}
else
{
echo "Invalid file";
}
?>
Tidak ada komentar:
Posting Komentar