Jeg er ikke særlig god til PHP, men har lige selv haft det samme problem. Jeg fandt et godt script der havde det indbygget.
<?
$extlimit = "yes"; //Hvis du kun vil have nogle specielle fil typer til skal du skrive "yes" nedenunder kan du angive hvilke.
$limitedext = array(".gif",".jpg",".png",".jpeg"); //Filertyper.
$sizelimit = "no"; //Vil du angive den maximume upload størrelse? angiv nedenunder.
$sizebytes = "200000"; //størrelse i bytes
$dl = "
http://www.Sjovert.dk/demo/up-down"; //url hvor filerne skal uploades til (skal være et bibliotek og husk chmod)
$absolute_path = "/home/sjovert/public_html/demo/up-down"; //Den absolute sti hvor filerne skal uploades til (dette havde jeg svært ved har en vejledning nederst)
$websiteurl = "
www.Sjovert.dk"; //Url til din side.
$websitename = "Sjovert"; Sidens navn
switch($action) {
default:
echo"
<html>
<head>
<title>Upload Or Download</title>
</head>
<body>
<a href=$PHP_SELF?action=upload>Upload File</a>
<a href=$PHP_SELF?action=download>Download File</a>
<a href=$websiteurl>Return to $websitename</a>
<br><br>
Powered by <a href=http://www.zachwhite.com/>PHP Uploader Downloader</a>
</body>
</html>";
break;
case "download":
echo "
<html>
<head>
<title>File Download</title>
</head>
<body><a href=$PHP_SELF?action=upload>Upload File</a> <a href=$websiteurl>Return to $websitename</a>";
$list = "<table width=700 border=1 bordercolor=#000000 style=\"border-collapse: collapse\">";
$list .= "<tr><td width=700><center><b>Click To Download</b></center></td></tr>";
$dir = opendir($absolute_path);
while($file = readdir($dir)) {
if (($file != "..") and ($file != ".")) {
//Download files with spaces fix by Kokesh
$list .= "<tr><td width=700><a href='$dl/$file'>$file</a></center></td></tr>";
}
}
$list .= "</table>";
echo $list;
echo"
<br><br>
Powered by <a href=http://www.zachwhite.com/>PHP Uploader Downloader</a>
</body>
</html>";
break;
case "upload":
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>
Powered by <a href=http://www.zachwhite.com/>PHP Uploader Downloader</a>
</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>
Powered by <a href=http://www.zachwhite.com/>PHP Uploader Downloader</a>
</body>
</html>";
break;
}
?>
Absolute Sti:
Sæt dette ind i et php dokument og upload det så kan du se hvad din absolute sti er.
<?php
echo "<html>" . $_SERVER["DOCUMENT_ROOT"] . "</html>";
?>