Hi,
This is a part of a scrpit I have for managing a symopsium website -> abstract submisison. Try and play wit hhtis. It should be ready to go, but I did some stripping before posting: I may have stripped too much..
$absolute_path = "../uploads/"; // Absolute path to where files are uploaded
$size_limit = "yes"; // do you want a size limit yes or no.
$limit_size = "1000000"; // How big do you want size limit to be in bytes
$limit_ext = "yes"; // do you want to limit the extensions of files uploaded
$ext_count = "2"; // total number of extensions in array below
$extensions = array(".doc", ".txt"); // List extensions you want files uploaded to be
// -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
switch($upload)
{
default:
$body .= "
<b>Upload of abstracts.</b><br>
The following restrictions apply:
<ul>
<li>File extension must be <b>";
if ($limit_ext != "yes")
{
$body .= "any extension";
}
else
{
$ext_count2 = $ext_count+1;
for($counter=0; $counter<$ext_count; $counter++)
{
$body .= " $extensions[$counter]";
}
}
if (($limit_size == "") or ($size_limit != "yes"))
{
$limit_size = "any size";
}
else
{
$limit_size .= " bytes";
}
$body .= "
</b>
</li>
<li>Maximum file size is 300 words</font></li>
<li>Do not use spaces in the filename</font></li>
<li>Do not use 'special' characters (/,*,\,etc) in the filename.</li>
</ul>
<form method=\"POST\" action=\"abstract.php\" enctype=\"multipart/form-data\"> // Adapt this to match your filename
<table><tr>
<td class=formlabel>File:</td><td><input class=\"formel_1\" type=\"hidden\" name=\"upload\" value=\"doupload\">
<input class=\"formel_1\" type=file name=file size=30></td></tr><tr>
<td class=formlabel></td><td>
<button class=\"formel_1\" name=\"submit\" type=\"submit\">Upload</button></td></tr>
</table>
</p>
</form>
";
break;
case "doupload":
$time = time();
$nutijd = date("Ymd_g_ia");
$today = date("Ymd");
$old_name = $_FILES[file][name];
$file_name = $_FILES[file][tmp_name];
$file_size = $_FILES[file][size];
$justfile = $_SESSION[user_extra]."_".$_SESSION[fname]."_".$_SESSION[name]."_".$nutijd."_".$_FILES[file][name];
$newfile = $absolute_path.'/'.$justfile;
$endresult = "
Thank you for submitting your abstract.
<p>The file $old_name has been uploaded succesfully.</p>";
if ($file_name == "")
{
$endresult = "No file selected";
}
else
{
if(file_exists("$absolute_path/$file_name"))
{
$endresult = "File Already Existed";
}
else
{
if (($size_limit == "yes") && ($limit_size < $file_size))
{
$endresult = "File was to big";
}
else
{
$ext = strrchr($old_name,'.');
if (($limit_ext == "yes") && (!in_array($ext,$extensions)))
{
$endresult = "File is wrong type";
}
else
{
move_uploaded_file($file_name, $newfile) or $endresult = "Couldn't Copy File To Server";
}