Hey 9rules people!
I am on the look-out for some scripts I need for a small project.
1. I need a directory script, I need to be able to point the script at a folder and be able to list the directory in another file. Ex: Directory is viewed in the root, but it is showing the files located in /files/
(if the above script has a feature that will allow me to password protect the file you have hit the jackpot, idealy)
2. A uploading script, that I can point to the /files/ folder.
PHP btw. Thanks alot any tips and i'm in yor dept.
-Phiip

7 Comments
Philip
Written Feb. 7, 2007 / Report /
Nobody? I just need the index scrit now.
paularms
Written Feb. 7, 2007 / Report /
Let's see if this works...
<?php- '.$file.' '.'
'."\n";
if ($handle = opendir($_SERVER['DOCUMENT_ROOT'].'/files')) {
while (false !== ($file = readdir($handle))) {
if (
$file != "." &&
$file != ".."
) {
$lastmodified = filemtime($file);
echo '
}
}
}
?>
paularms
Written Feb. 7, 2007 / Report /
crap it didn't... hold on...
<?php- '.$file.' '.'
'."\n";
if ($handle = opendir($_SERVER['DOCUMENT_ROOT'].'/files')) {
while (false !== ($file = readdir($handle))) {
if (
$file != "." &&
$file != ".."
) {
$lastmodified = filemtime($file);
echo '
}
}
}
?>
paularms
Written Feb. 7, 2007 / Report /
9Rules formatting hates me...
replace '^^' with < or >
<?php
if ($handle = opendir($_SERVER['DOCUMENT_ROOT'].'/files')) {
while (false !== ($file = readdir($handle))) {
if (
$file != "." &&
$file != ".."
) {
$lastmodified = filemtime($file);
echo '^^a href="/files/'.$file.'/"^^'.$file.'^^/a^^'."\n";
}
}
}
?>
Philip
Written Feb. 8, 2007 / Report /
This is what I used, but since this only displays the title I will be changing this later, I would like all the specs to show, size, date.
<?php$open = opendir("files/"); // Opens Folder
while(false !== ($read = readdir($open))) // Loops Through
if($read !== "error_log" && $read !== ".snifthumbs" && $read !== ".." && $read !== ".") // Removes unwanted files
print("<a href='files/$read'>$read</a><br />"); // Correct Linkage
?>
eddie
Written Feb. 8, 2007 / Report /
As for the file upload the html:
<form enctype="multipart/form-data" action="post.php" method="post"><p>
<input type="hidden" name="MAX_FILE_SIZE" value="1048576" />
<input type="file" name="file" size="30" /><br />
<input type="submit" value="Upload" />
</p>
</form>
and post.php should have this in it:
$file = $_FILES['file'];if($file['error'] != 0){
print "The file you tried to upload was to big.";
}elseif(file_exists("./files/".$file['name'])){
print "A file with that name already exists.";
}elseif(move_uploaded_file($file['tmp_name'], "./files/".$file['name'])){
print "File Uploaded";
}
Sorry if the formatting is all screwy
StevenBao
Written Feb. 8, 2007 / Report /
This is what I use.
<?php
$filenum = 5;
$file_dir = "DIRECOTRY - like /home2/steven/public_html/whsb/member/files/";
if ($_POST) {
?>
<script type="text/javascript">var f = document.getElementById('browsefiles'); f.src = f.src;</script>
<?php
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newfile = $file_dir.$_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
$j++;
}
}
}
if (isset($j)&&$j>0) echo "<strong>Uploaded!<br /></strong>";
echo "<form method='post' enctype='multipart/form-data'>";
for($i=0;$i<$filenum;$i++) {
echo "<input type='file' name='myfiles[]' size='40' /><br />";
}
echo "<input type='submit' name='action' value='Upload!' />";
echo "</form>";
?>