Hey I have had a problem about a php file called register.php that when the web browser directly asked to open register.php an error would display because no username was sent to the php file register.php. I fixed my syntax checking by using the code
PHP Code:
if (!isset($_POST["username"]) || !$_POST["username"])
Now I am having a similar problem while trying to create upload_file.php that uploads files but if someone accesses upload_file.php directly my new php server gives me a butt load of errors that insist that $_FILE['file'] is not defined. So I was wondering if any code show me how to properly check to see if $_FILE['file'] exists so that if it doesnt I could just print a message saying to make sure to enter a file and then exit the php script.
Below is the current php file that works but will print errors if accessed directly with a web browser. Also below that I am posting the html page so you guys can test if.
upload_file.php
PHP Code:
<?php
if($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
if($_FILES["file"]["size"] > 570000)
{
echo "File size to exceeds 5.7 Megabytes";
exit;
}
if(file_exists("uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
exit;
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/" . $_FILES['file']['name']);
echo "Upload : " . ($_FILES["file"]["name"]) . "<br>";
echo "Type : " . ($_FILES["file"]["type"]) . "<br>";
echo "Size : " . ($_FILES["file"]["size"] / 1024) . " Kb<br>";
echo "TMP File : " . $_FILES["file"]["tmp_name"] . "<br>";
echo "Stored In: " . "uploads/" . $_FILES["file"]["name"];
}
}?>
upload_file.html
Code:
<html>
<head>
<title>Blank HTML</title>
<meta name="author" content="Eric Justin Allan">
<style type="text/css">
body
{
background-image: url('jpg/200829053409-8159.jpg');
color:blue;
}
a
{
text-decoration:none;
color:white;
}
</style>
</head>
<body>
<p>Unpload files smaller then 5.7 megabytes preferably small files but definetly cool files
<form action="upload_file.php" method="post" enctype="multipart/form-data">
<font color="red">*</font> Filename:<input type="file" name="file" id="file" />
<input type="submit" name="submit" value="Submit" /></form>
</body>
</html>