26. november 2003 - 10:54Der er
10 kommentarer og 1 løsning
fejl i filesystem funktion
Jeg har lavet en classe, til at lave nogle oprationer på filsystemet, men jeg kan ikke rigtig få det til at virke efter hindsigten!
Fejl:
Warning: chdir(): No such file or directory (errno 2) in /var/hosting/dsl.dk/k47/htdocs/k47/Dirfunctions.php on line 21
Warning: readdir(): supplied argument is not a valid Directory resource in /var/hosting/dsl.dk/k47/htdocs/k47/Dirfunctions.php on line 22 --------- Ang fejl besked: det angivet dir, test, findes ---------- Kilde kode: test.php
<? require("Dirfunctions.php"); $teksts = new Dirfunctions("test"); echo $teksts->getdirs(); ?>
Dirfunctions.php
<?php class Dirfunctions { #The dir to operat on var $dir;
################################################# # Function name: getdirs # # # # args: none # # # # returns: an array of the dirs in the dir that # # is operated uppon # # # ################################################# function getdirs() { $dh = opendir($dir); #saves the cwd, for later return $initial_path=getcwd(); chdir($dir); while (false !== ($filename = readdir($dh))) { if(is_dir($filename)) { $dirs[] = $filename; } } #returns to the cwd chdir($initial_path); return $dirs; }
################################################# # Function name: getfiles # # # # args: none # # # # returns: an array of the files in the dir # # that is operated uppon # # # ################################################# function getfiles() { $dh = opendir($dir); #saves the cwd for later return $initial_path=getcwd(); chdir($dir); while (false !== ($filename = readdir($dh))) { if(is_file($filename)) { $files[] = $filename; } } #return to the cwd chdir($initial_path); return $files; } }
function Dirfunctions($newDir) { #Check if the given dir exists if(file_exists($newDir)) { #Check if the given dir, real is a dir if(is_dir($newDir)) { #Sets var dir too $newDir $this->$dir = $newDir; } else { #The dir, isn't real a dir, but something else #Returns an error trigger_error("The defined dir, isn't a dir", E_USER_ERROR); } } else { #The dir, don't exists #Returns an error trigger_error("The defined dir don't exists", E_USER_ERROR); } } ?>
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
- Konstruktøren er nu flytte ind i klassen - rettet til $this->dir (flere steder) - debug-lag lagt ind.
klassen virker stadig ikke. Følgende resultat fås ved køresel af test.php:
The given dir is /var/hosting/dsl.dk/k47/htdocs/k47/test
The folder is: /var/hosting/dsl.dk/k47/htdocs/k47/testArray
------------------------------------------------------------------ Jeg kan ikke se hvorfor der sættes Array bag på /var/hosting/dsl.dk/k47/htdocs/k47/test ----------------------------------------------------
Ny udgave af Dirfunctions.php: <?php class Dirfunctions { #The dir to operat on var $dir;
################################################# # Function name: getdirs # # # # args: none # # # # returns: an array of the dirs in the dir that # # is operated uppon # # # ################################################# function getdirs() { echo "<br>The folder is:<br> $this->dir"; $dh = opendir($this->dir); #saves the cwd, for later return $initial_path=getcwd(); chdir($this->dir); while (false !== ($filename = readdir($dh))) { if(is_dir($filename)) { $dirs[] = $filename; } } closedir($dh); #returns to the cwd chdir($initial_path); return $dirs; }
################################################# # Function name: getfiles # # # # args: none # # # # returns: an array of the files in the dir # # that is operated uppon # # # ################################################# function getfiles() { echo "<br>The folder is:<br> $this->dir"; $dh = opendir($this->dir); #saves the cwd for later return $initial_path=getcwd(); chdir($this->dir); while (false !== ($filename = readdir($dh))) { if(is_file($filename)) { $files[] = $filename; } } closedir($dh); #return to the cwd chdir($initial_path); return $files; }
function Dirfunctions($newDir) { echo "<br>The given dir is $newDir<br>"; #Check if the given dir exists if(file_exists($newDir)) { #Check if the given dir, real is a dir if(is_dir($newDir)) { #Sets var dir too $newDir $this->dir = $newDir; } else { #The dir, isn't real a dir, but something else #Returns an error trigger_error("The defined dir, isn't a dir", E_USER_ERROR); } } else { #The dir, don't exists #Returns an error trigger_error("The defined dir don't exists", E_USER_ERROR); } }
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.