View Full Version : Viewers uploading/downloading files
What I am looking to do is setup a portion of my webspace that I have on my school's server where my friends and I can easily upload and download files. Doesn't have to look nice, could just be a directory of sorts where I and other people can view the files and upload new ones or download the ones there from any location. If anyone knows of a simple way to do this please let me know. Password protected would be preferred but not necessary as no one except the people I give the url to look at my site, and password protection might be over my head. I have dreamweaver MX and use that to make the pages, if that makes a difference. Thanks.
nathan_lamothe
04-23-2006, 02:05 AM
Maybe it is your school as in you are the principal, or you are the sysadmin...
But if I was division tech at your school, you wouldn't touch my server with a 10 foot pole... ;-)
Welcome to the forums 2Fly...I can't help you, but someone here likely can...
mlseim
04-23-2006, 05:32 AM
I'm assuming your server allows PHP scripting ...
First, you have this form that can allow the upload of 1,2,3 or whatever
number of files. (set the number in the form 'num') ... also, a password needs
to be entered before clicking submit.
<form action='upload.php' method='post' enctype='multipart/form-data'>
<input type='hidden' name='num' value='3'>
Select File 1: <input type='file' name='file1'><br>
Select File 2: <input type='file' name='file2'><br>
Select File 3: <input type='file' name='file3'><br>
Enter Password: <input type='text' name='pass' value=''>
<input type='Submit' value='Upload'>
</form>
Then, you have this PHP script called "upload.php". This reads the
form values and uploads the files into a directory called "uploads".
The permissions must be set on that directory so you can write into it.
Set those with your webhost directory settings.
<?php
//Get the number of files to be uploaded and password "sesame"
$num = $_POST['num'];
$pass = $_POST['pass'];
if ($pass eq "sesame") //check password
{
//Start the Loop
for ($x = 1; $x <= $num; $x++)
{
//Make sure a file has been selected for upload
if (is_uploaded_file($_FILES['file'.$x]['tmp_name']))
{
//Get the size of the current file
$size = $_FILES['file'.$x]['size'];
//Make sure that this file is <= 500KB
if ($size <= 5000000)
{
//Move the uploaded file
if (move_uploaded_file($_FILES['file'.$x]['tmp_name'],'uploads/'.$_FILES['file'.$x]['name']))
{
//Display message
echo "<html>";
echo "<head></head>";
echo "<body>";
echo "<table cellpadding='10' cellspacing='15' width='500' align='center'>";
echo "<tr><td bgcolor='#F1F8FF'>";
echo "<center> File: <b>".$_FILES['file'.$x]['name'] . "</b> uploaded.</center><br>";
echo "</td></tr>";
echo "</table>";
echo "</body></html>";
}
else
{
//Unable to move file
echo "File: ".$_FILES['file'.$x]['name']. " error moving file.<BR>";
}
}
else
{
//File too large
echo "File: " . $_FILES['file'.$x]['name'] . "File Too Large.<BR>";
}
}
else
{
//No file selected
echo "No File Selected.<BR>";
}
} //End of loop
}
else
{
echo "Invalid Access.<BR>";
}
?>
To view and download the files, simply go to that directory with your
browser. If the directory has no file called "index.html" or "index.htm",
it will list all the files in the directory.
Like Nathan said, if someone finds out about this, they could upload
5,000,000 files and crash the server ... doing a lot of damage.
They could also upload a .php script that erases and corrupts files
on your server. Use this to get you started, but look for a better script
that controls the filetypes that can be uploaded. The script above is
a "bare-bones" no checking script.
nathan_lamothe
04-23-2006, 08:29 AM
Neat.
Looks like PHP goes high on my list once javascript is solid and html/css is playing on the beach rather than swimming across a riptide.
mlseim - I love that sig.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.