Okay, first off, I've never done anything with PHP before... my programming experience consists of - $hello = "Hello World!" - in perl and that's about it. So bare with.
heres the code I have now:
<?php
//Check if a file has been selected
if (is_uploaded_file($_FILES['uploaded']['tmp_name']))
{
//Get the Size of the File
$size = $_FILES['uploaded']['size'];
$fileName = $_FILES['uploaded']['name'];
//Make sure that $size is less than 20MB
if ($size > 20000000)
{
//Print the error
echo "
<html>
<head>
<title>Thank you!</title>
<style type=text/css>
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #333333;
}
a:link {
color: #336699;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #336699;
}
a:hover {
text-decoration: underline;
color: #003399;
}
a:active {
text-decoration: none;
color: #003399;
}
-->
</style></head>
<body>
File Too Large. Please try again.<br><a href=index.htm>Return</a>
</body>
</html>";
exit();
}
//Get the password
$password = $_POST['password'];
//Determine User
if ($password == 'user1')
{
$dir = 'user1';
}
else if ($password == 'user2')
{
$dir = 'user2';
}
else
{
echo "
<html>
<head>
<title>Thank you!</title>
<style type=text/css>
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #333333;
}
a:link {
color: #336699;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #336699;
}
a:hover {
text-decoration: underline;
color: #003399;
}
a:active {
text-decoration: none;
color: #003399;
}
-->
</style></head>
<body>
You have entered an incorrect password, please <a href=index.htm>return</a> and try again.
</body>
</html>";
exit();
}
//Move the File to the Directory of your choice
if (move_uploaded_file($_FILES['uploaded']['tmp_name'],"memdirs/".$dir."/".$_FILES['uploaded']['name'])) {
//tell the user that the file has been uploaded
echo "
<html>
<head>
<title>Thank you!</title>
<style type=text/css>
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #333333;
}
a:link {
color: #336699;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #336699;
}
a:hover {
text-decoration: underline;
color: #003399;
}
a:active {
text-decoration: none;
color: #003399;
}
-->
</style></head>
<body>
Click on <a href=memdirs/".$dir."/".$fileName.">".$fileName."</a> to view file!<br><a href=index.htm>Return Home</a>
</body>
</html>";
//Include the Next Page
exit();
}
else
{
//Print error
echo "
<html>
<head>
<title>Thank you!</title>
<style type=text/css>
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #333333;
}
a:link {
color: #336699;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #336699;
}
a:hover {
text-decoration: underline;
color: #003399;
}
a:active {
text-decoration: none;
color: #003399;
}
-->
</style></head>
<body>
Unable to move the File.<br><a href=index.htm>Return</a>
</body>
</html>";
exit();
}
}
else
{
//Print error
echo "
<html>
<head>
<title>Thank you!</title>
<style type=text/css>
<!--
body,td,th {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #333333;
}
a:link {
color: #336699;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #336699;
}
a:hover {
text-decoration: underline;
color: #003399;
}
a:active {
text-decoration: none;
color: #003399;
}
-->
</style></head>
<body>
No File Selected.<br><a href=index.htm>Return</a>';
</body>
</html>";
//Include the Form
include 'index.htm';
exit();
}
?>
Don't make fun of me cause I know that just about everything in that can be done alot easier, lol...
I want to make it so that when a certain password is entered it changes the directory, of which the selected file is uploaded to, acording to that password. And theres so much wrong with it now that I don't know where to start to fix it.
Questions:
- Will "memdirs/".$dir."/" work as the location of where the file is uploaded
and 2. Will <a href=memdirs/".$dir."/".$fileName.">".$fileName."</a> work as a link to that file.
Thanks a whole lot.
Anything will help, turst me.