Adding Password to single function
Posted: Mon Feb 14, 2005 8:40 pm
Hello Everybody
I have a what I hope to be a simple code question. I have an upload/download script which originated as a download and I have been customizing to my likings. As I am still rather new to PHP, I have not been able to correctly write a code line for a password for a single function (the upload portion). I would like all of our members to be able to download but only a few of us to upload.
Here is what I have. The upload script starts at Line 45. Thank You.
Jaz
I have a what I hope to be a simple code question. I have an upload/download script which originated as a download and I have been customizing to my likings. As I am still rather new to PHP, I have not been able to correctly write a code line for a password for a single function (the upload portion). I would like all of our members to be able to download but only a few of us to upload.
Here is what I have. The upload script starts at Line 45. Thank You.
Jaz
Code: Select all
<html>
<head>
<title>File Management System</title>
</head>
<body>
<p align="center"><img border="0" src="../images/boardareatitle.jpg" width="590" height="225"></p>
<?
$extlimit = "no"; //Do you want to limit the extensions of files uploaded
$limitedext = array(".gif",".jpg",".png",".jpeg",".doc",".xls"); //Extensions you want files uploaded limited to.
$sizelimit = "no"; //Do you want a size limit, yes or no?
$sizebytes = "2000000"; //size limit in bytes
$dl = "http://www.Mywebsite.ca/BoardMember/BoardMinutes"; //url where files are uploaded
$absolute_path = "/usr/home/public_html/www.Mywebsite.ca/BoardMember/BoardMinutes"; //Absolute path to where files are uploaded
$websiteurl = "http://www.Mywebsite.ca/CLASBoardMember/index.htm"; //Url to you website
$websitename = "My Web Site"; //Line 15
switch($action) {
default:
case "download":
echo "
<html>
<head>
<title>Board Meeting MinutesFile Download</title>
</head>
<body>
<center><a href=$websiteurl>Return to $websitename</a>";
$list = "<center><table width=700 border=2 bordercolor=#000000 style="border-collapse: collapse">";
$list .= "<tr><td width=700><center><b>Click To Open</b></center></td></tr>";
$dir = opendir($absolute_path);
while($file = readdir($dir)) {
if (($file != "..") and ($file != ".")) {
$list .= "<tr><td width=700><center><a href='$dl/$file'>$file</a></center></td></tr>"; //Line 33
}
}
$list .= "</table></center>";
echo $list;
echo"
<br><br>
Having Trouble? Conact the <a href=mailto:webmaster@Mywebsite.ca>Webmaster</a>
</body>
</html>";
break;
case "upload": //Line 45
echo"
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form method=POST action=$PHP_SELF?action=doupload enctype=multipart/form-data>
<p>File to upload:<br>
<input type=file name=file size=30>
<p><button name=submit type=submit>
Upload
</button>
</form>
<br><br>
</body>
</html>";
break;
//File Upload
case "doupload":
$dir = "dir";
if ($file != "") {
if (file_exists("$absolute_path/$file_name")) {
die("File already exists");
}
if (($sizelimit == "yes") && ($file_size > $sizebytes)) {
die("File is to big. It must be $sizebytes bytes or less.");
}
$ext = strrchr($file_name,'.');
if (($extlimit == "yes") && (!in_array($ext,$limitedext))) {
die("The file you are uploading doesn't have the correct extension.");
}
@copy($file, "$absolute_path/$file_name") or die("The file you are trying to upload couldn't be copied to the server");
} else {
die("Must select file to upload");
}
echo "
<html>
<head>
<title>File Uploaded</title>
</head>
<body>";
echo $file_name." was uploaded";
echo "<br>
<a href=$PHP_SELF?action=upload>Upload Another File</a>
<a href=$PHP_SELF?action=download> Download File</a>
<a href=$websiteurl> Return to $websitename</a><br><br>
</body>
</html>";
break;
}
?>