I have been messing about with php for a couple of years now, just on and off, mostly dabbling with a lightweight uploading script I made. This has been bothering me for some time so I thought I would ask here for some tips!
I have made a directory browsing script, that allows you to select a directory to upload to, using the GET function.
Here's the script: ($directory is the directory chosen for uploading to, $multiupload is just to select how many upload forms you want)
Code: Select all
<?php
$directory = @$_GET['folder'];
$multiupload = @$_GET['multiup'];
$direx = explode('/', $directory);
$direxcount = count($direx);
$direxreplaced = str_replace('/'.$direx[$direxcount-1], '', $directory);
$opendir1=opendir('./');
while (false != ($filefolder = readdir($opendir1))){
if ($filefolder != '.' && $filefolder != '..' && $filefolder != 'cfg.php' && $filefolder != 'index.php') {
if (is_dir($filefolder)){
if ($filefolder == $direx[0]){ echo $directory.'/<BR>';}else{
echo('<a href="?folder='.$filefolder.'&mutliup='.$multiupload.'">'.$filefolder.'/</a><BR>'); }
if ($filefolder == $direx[0]){
if ($direxcount > 1){
echo '< <a href="?folder='.$direxreplaced.'&multiup='.$multiupload.'">Back to: '.$direxreplaced.'</a><BR>';}}
$opendir2 = @opendir($directory);
while (false != ($folder2 = @readdir($opendir2))) {
if (!is_dir($folder2)) {
$ext2 = strrchr($directory.'/'.$folder2, '.');
$ext2 = strtolower(substr($ext2, 1));
$finf = array($folder2);
$len2 = count($finf);
for ($i2 = 0; $i2 < $len2; $i2++) {
if ($ext2 == ""){
if ($filefolder == $direx[0]){
echo '<a href="?folder='.$directory.'/'.$finf[$i2].'">/'.$finf[$i2].'</a><BR>';
$subfolder = 1;
}}}}}echo '<BR>';
//end of opendir1
}}}
//end of opendir2
?>
Stickman/Images/
< Back to: Stickman
/Design
/Work
/Photos
/Random
/Screenshots
This code is very sloppy, it will grab the main directories and plonk them in a list, that I want people to upload to.
Then it keeps that structure, and places the sub directories from the main folder selected, under the main folder in the list. ( I could have it pop to the top instead, but I find that confusing )
Problem is, it sticks the main folder at the start of the link, and the subdirectories in one long string so, it makes (1)$directory.(2)$finf[$i2] like this (1)Stickman/(2)Images/Random/funny
So as for the link "< Back to: [Foldername]" I made something which I knew how to do, which was just to explode the directories and remove the last name off the end using the explode array to display a 'Go back to the last folder' Sort of thing...
What I wanted was to have a link for each sub-directory all the way back to the main directory, instead of just a 'go back one' link... Any help on improving this would make my day haha, if you need any more code let me know, or even the full page.
Thanks,
Stick
PS Is there any way to time an upload, so that once an upload button is pressed it sets a timer off and stop once all files are uploaded?