27. marts 2007 - 19:58Der er
1 kommentar og 1 løsning
Loade bibliotek i select multiple
Hey experts!
Jeg har lavet et system hvor man kan uploade filer og browse rundt, nu skal jeg så finde en måde hvor man kan vedhæfte disse filer fra serveren til et job i systemet.
Så jeg tænkte på at loade hele bruger biblioteket ind i en "select multiple", men hvad gør jeg med under biblioteker?
Jeg har bare brug for en metode så jeg kan vælge flere filer fra serveren og tilføje selve stien til en streng.
arhhaa... fandt ud af der, men er der nogen der kan hjælpe med at sortere arrayet efter path?
<html>
<head> <title></title> </head>
<body>
<?php /* The below function will list all folders and files within a directory It is a recursive function that uses a global array. The global array was the easiest way for me to work with an array in a recursive function *This function has no limit on the number of levels down you can search. *The array structure was one that worked for me. ARGUMENTS: $startdir => specify the directory to start from; format: must end in a "/" $searchSubdirs => True/false; True if you want to search subdirectories $directoriesonly => True/false; True if you want to only return directories $maxlevel => "all" or a number; specifes the number of directories down that you want to search $level => integer; directory level that the function is currently searching */ function filelist ($startdir, $searchSubdirs, $directoriesonly, $maxlevel="all", $level=1) { //list the directory/file names that you want to ignore $ignoredDirectory[] = "."; $ignoredDirectory[] = ".."; $ignoredDirectory[] = "_vti_cnf"; global $directorylist; //initialize global array if (is_dir($startdir)) { if ($dh = opendir($startdir)) { while (($file = readdir($dh)) !== false) { if (!(array_search($file,$ignoredDirectory) > -1)) { if (filetype($startdir . $file) == "dir") { //build your directory array however you choose; //add other file details that you want. $directorylist[$startdir . $file]['level'] = $level; $directorylist[$startdir . $file]['dir'] = 1; $directorylist[$startdir . $file]['name'] = $file; $directorylist[$startdir . $file]['path'] = $startdir; if ($searchSubdirs) { if ((($maxlevel) == "all") or ($maxlevel > $level)) { filelist($startdir . $file . "/", $searchSubdirs, $directoriesonly, $maxlevel, $level + 1); } } } else { if (!$directoriesonly) { //if you want to include files; build your file array //however you choose; add other file details that you want. $directorylist[$startdir . $file]['level'] = $level; $directorylist[$startdir . $file]['dir'] = 0; $directorylist[$startdir . $file]['name'] = $file; $directorylist[$startdir . $file]['path'] = $startdir; }}}} closedir($dh); }} return ($directorylist); } $files = filelist("c:/1/",1,0); // call the function /* foreach ($files as $list) {//print array echo "Directory: " . $list['dir'] . " => Level: " . $list['level'] . " => Name: " . $list['name'] . " => Path: " . $list['path'] ."<br>"; }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.