her er en fuld upload script:
index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="
http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>uploads</title>
</head>
<!--*****************************-->
<pre>
<?
$dirname = "../ibmuyt/"; //Hvor skal den lede efter filer?
$dirhandle = opendir($dirname); //Åben mappen
while($file = readdir($dirhandle)) //Loop gennem mappen
{
if ($file != "." && $file != "..") //Fjern . og ..
{
if (is_file($dirname.$file)) //Find ud af om det er en fil eller en mappe
{
echo "Fil: <a href=\"../ibmuyt/" . $file . "\">" . $file . "</a><br>";
}
else
{
echo "mappe: " . $file . "<br>";
}
}
}
?> </pre>
</body>
</html>
upload.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="
http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload a theme</title>
</head>
<body>
<form action="uploader.php" method="post"
enctype="multipart/form-data">
<input type="file" name="file" id="file" />
<br />
<input name="submit" type="submit" value="Upload" />
</form>
</body>
</html>
uploader.php:
<body>
<p>
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 5120) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("../ibmuytc/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../ibmuytc/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../ibmuytc/" . $_FILES["file"]["name"];
print "<br><br><a href='../ibmuytc/index.php' style='cursor:pointer;'>Goto: ibmuytc</a>";
}
}
?>
</p>
</body>