write some PHP code type in an example of a file upload rout
write some PHP code:
type in an example of a file upload routine in PHP.
Solution
index.html
<html>
<html>
<body>
<form action=\"up.php\" method=\"post\" enctype=\"multipart/form-data\">
Select image to upload:
<input type=\"file\" name=\"fileToUpload\" id=\"fileToUpload\">
<input type=\"submit\" value=\"Browse Image\" name=\"submit\">
</form>
</body>
</html>
up.php:
<?php
function uploadfile()
{
$target_dir = \"uploads/\";
$target_file = $target_dir . basename($_FILES[\"fileToUpload\"][\"name\"]);
if(isset($_POST[\"submit\"]))
{
if (move_uploaded_file($_FILES[\"fileToUpload\"][\"tmp_name\"], $target_file)) //php funcrion to upload file
{
echo \"The file \". basename( $_FILES[\"fileToUpload\"][\"name\"]). \" has been uploaded.\";
}
else
{
echo \"Sorry, there was an error.\";
}
}
}
uploadfile();
?>
Note : Place these two files in a directory and create folder \" Files \" in current directory,and put directory any webserver to run
