[php] Function return array

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • InfoTracer
  • Registratie: November 2001
  • Laatst online: 05:58
sorry maar hij wil me text + code niet versturen probeer het ff in delen aub dit topic niet sluiten

preview wil hij ook niet doen

ik zal mijn text ff in een txt bestandje zetten en de link posten

hij wou ook niet eens een txt bestand uploaden er zit waarschijnlijk iets fout maar het zou zo moeten werken


sorry voor het ongemak

thanx bthy

het versturen vanaf me server doet hij wel goed er zit waarschijnlijk iets niet goed met me pc
hieronder norgmaals de vraag alvast bedankt

Na hier op got een functie te hebben gevonden om dirs te kopieeren heb ik deze helemaal uitgezocht en daarna ben ik hem een beetje gaan verbouwen zodat ik de datums van mappen en bestanden uit een map kan vergelijken met 1 datum. Als de datum van het bestand of map later is dan de opgegeven datum dan echot ie hem en zou hem in een array moeten zetten. Dat in die array zetten die ie dus niet.
En heb echt geen id waarom niet aangezien hij hem wel echot.

Hieronder de source:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

function rcopy($itempath,$lastupdate,$updated)
    {
        // gives back the real patch name
        $theitem = realpath($itempath);
        // if $theitem is a real dir then it returns True and goes on
        if(is_dir($theitem)) 
            {
                // gives something back that readdir can use
                $dirhandle = opendir($theitem);

            // will start a loop that will read the dir and places all the elements in an array named $files        
            while(false !== ($files = readdir($dirhandle)))
                {
                // Will skip " . " and " .. " as files
                if(($files !== ".") && ($files !== ".."))
                    {
                    // checks if the element is a dir
                    if(is_dir("".$theitem."/".$files.""))
                        {
                            $dirdate = filemtime("".$theitem."/".$files."");
                            $dirnames = realpath("".$theitem."/".$files."");
                            if($lastupdate < $dirdate)
                            {
                                array_push($updated,$dirnames);
                                echo " dir ".$dirnames." $dirdate <BR>";
                            }
                            // if the element is a dir it will give the dir name back to $subdir
                            $subdir = realpath("".$theitem."/".$files."");
                            // and then it will run the script again from the top of the function only with the sub dir name
                            rcopy($subdir,$lastupdate,$updated);
                        }
                    // if the element wasn't a dir then it will check if it's a file
                    elseif(is_file("".$theitem."/".$files.""))
                        {
                            $filedate = filemtime("".$theitem."/".$files."");
                            $filenames = realpath("".$theitem."/".$files."");
                            if($lastupdate < $filedate)
                            {
                                array_push($updated,$filenames);
                                echo " file ".$filenames." $filedate <BR>";
                            }
                        }
                    }
                }
                //closes the dir
                closedir($dirhandle);
            }
        return $updated;
    }

$updated = array();
$tekopieeren = "sync";
$lastupdate = "1115763029";

$updated1 = rcopy($tekopieeren,$lastupdate,$updated);

?>
<PRE>
<?
print_r($updated1);
?>
<PRE>
<?

?>


ik heb ook al geprobeerd $updated[] = $filenames; ivp array_push($updated,$filenames);

maar dit geeft het zelfde resultaat.

hier een voorbeeld van de output:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
file c:\apache\apache\htdocs\dylan\sync\hallotest.txt 1115763901
dir c:\apache\apache\htdocs\dylan\sync\hallotestdir 1115770955
file c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir.txt 1115770940
dir c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir1 1115768283
file c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir1\New Text Document.txt 1115768283
file c:\apache\apache\htdocs\dylan\sync\tdgfhfgjnvgjnfgh.txt 1115768530
file c:\apache\apache\htdocs\dylan\sync\test.php 1115763138

Array
(
    [0] => c:\apache\apache\htdocs\dylan\sync\hallotest.txt
    [1] => c:\apache\apache\htdocs\dylan\sync\hallotestdir
    [2] => c:\apache\apache\htdocs\dylan\sync\tdgfhfgjnvgjnfgh.txt
    [3] => c:\apache\apache\htdocs\dylan\sync\test.php
)

[ Voor 254% gewijzigd door InfoTracer op 20-05-2005 19:44 ]


Acties:
  • 0 Henk 'm!

  • Blacksnak
  • Registratie: Oktober 2001
  • Laatst online: 07-07-2024
*sluit topic* ?
Modbreak:Topicreport knopje? :/

[ Voor 56% gewijzigd door NMe op 11-05-2005 14:39 ]


Acties:
  • 0 Henk 'm!

  • sjroorda
  • Registratie: December 2001
  • Laatst online: 14:31
InfoTracer schreef op woensdag 11 mei 2005 @ 11:19:
sorry maar hij wil me text + code niet versturen probeer het ff in delen aub dit topic niet sluiten
Daar heb je de preview voor...

Acties:
  • 0 Henk 'm!

Verwijderd

copy/paste van je txt file hier lukt mij wel ..
Na hier op got een functie te hebben gevonden om dirs te kopieeren heb ik deze helemaal uitgezocht en daarna ben ik hem een beetje gaan verbouwen zodat ik de datums van mappen en bestanden uit een map kan vergelijken met 1 datum. Als de datum van het bestand of map later is dan de opgegeven datum dan echot ie hem en zou hem in een array moeten zetten. Dat in die array zetten die ie dus niet.
En heb echt geen id waarom niet aangezien hij hem wel echot.

Hieronder de source:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

function rcopy($itempath,$lastupdate,$updated)
    {
        // gives back the real patch name
        $theitem = realpath($itempath);
        // if $theitem is a real dir then it returns True and goes on
        if(is_dir($theitem)) 
            {
                // gives something back that readdir can use
                $dirhandle = opendir($theitem);

            // will start a loop that will read the dir and places all the elements in an array named $files        
            while(false !== ($files = readdir($dirhandle)))
                {
                // Will skip " . " and " .. " as files
                if(($files !== ".") && ($files !== ".."))
                    {
                    // checks if the element is a dir
                    if(is_dir("".$theitem."/".$files.""))
                        {
                            $dirdate = filemtime("".$theitem."/".$files."");
                            $dirnames = realpath("".$theitem."/".$files."");
                            if($lastupdate < $dirdate)
                            {
                                array_push($updated,$dirnames);
                                echo " dir ".$dirnames." $dirdate <BR>";
                            }
                            // if the element is a dir it will give the dir name back to $subdir
                            $subdir = realpath("".$theitem."/".$files."");
                            // and then it will run the script again from the top of the function only with the sub dir name
                            rcopy($subdir,$lastupdate,$updated);
                        }
                    // if the element wasn't a dir then it will check if it's a file
                    elseif(is_file("".$theitem."/".$files.""))
                        {
                            $filedate = filemtime("".$theitem."/".$files."");
                            $filenames = realpath("".$theitem."/".$files."");
                            if($lastupdate < $filedate)
                            {
                                array_push($updated,$filenames);
                                echo " file ".$filenames." $filedate <BR>";
                            }
                        }
                    }
                }
                //closes the dir
                closedir($dirhandle);
            }
        return $updated;
    }

$updated = array();
$tekopieeren = "sync";
$lastupdate = "1115763029";

$updated1 = rcopy($tekopieeren,$lastupdate,$updated);

?>
<PRE>
<?
print_r($updated1);

?>
<PRE>
<?

?>


ik heb ook al geprobeerd $updated[] = $filenames; ivp array_push($updated,$filenames);

maar dit geeft het zelfde resultaat.

hier een voorbeeld van de output:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
file c:\apache\apache\htdocs\dylan\sync\hallotest.txt 1115763901
dir c:\apache\apache\htdocs\dylan\sync\hallotestdir 1115770955
file c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir.txt 1115770940
dir c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir1 1115768283
file c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir1\New Text Document.txt 1115768283
file c:\apache\apache\htdocs\dylan\sync\tdgfhfgjnvgjnfgh.txt 1115768530
file c:\apache\apache\htdocs\dylan\sync\test.php 1115763138

Array
(
    [0] => c:\apache\apache\htdocs\dylan\sync\hallotest.txt
    [1] => c:\apache\apache\htdocs\dylan\sync\hallotestdir
    [2] => c:\apache\apache\htdocs\dylan\sync\tdgfhfgjnvgjnfgh.txt
    [3] => c:\apache\apache\htdocs\dylan\sync\test.php
)
ik heb ook al geprobeerd $updated[] = $filenames; ivp array_push($updated,$filenames);
probeer mss eens met $array[] =& $object ipv array_push($array, $object)

[ Voor 44% gewijzigd door Verwijderd op 11-05-2005 11:48 . Reden: reply onderaan geplaatst .. ]


Acties:
  • 0 Henk 'm!

  • InfoTracer
  • Registratie: November 2001
  • Laatst online: 05:58
Verwijderd schreef op woensdag 11 mei 2005 @ 11:35:
copy/paste van je txt file hier lukt mij wel ..


[...]


[...]

probeer mss eens met $array[] =& $object ipv array_push($array, $object)
na dat geprobeerd te hebben geeft hij dit weer

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
file c:\apache\apache\htdocs\dylan\sync\hallotest.txt 1115763901
dir c:\apache\apache\htdocs\dylan\sync\hallotestdir 1115770955
file c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir.txt 1115770940
dir c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir1 1115768283
file c:\apache\apache\htdocs\dylan\sync\hallotestdir\hallotestdir1\New Text Document.txt 1115768283
file c:\apache\apache\htdocs\dylan\sync\tdgfhfgjnvgjnfgh.txt 1115768530
file c:\apache\apache\htdocs\dylan\sync\test.php 1115763138

Array
(
    [0] => c:\apache\apache\htdocs\dylan\sync\testdoc2.txt
    [1] => c:\apache\apache\htdocs\dylan\sync\testmap2
    [2] => c:\apache\apache\htdocs\dylan\sync\testdoc2.txt
    [3] => c:\apache\apache\htdocs\dylan\sync\testdoc2.txt


de bestanden die in de array staan zijn juist bestanden die er niet in horen te staan

Acties:
  • 0 Henk 'm!

  • InfoTracer
  • Registratie: November 2001
  • Laatst online: 05:58
Na nog zelf wat geklote te hebben ben ik er toch uitgekomen zal vast wel niet mooi geprogrameerd zijn maar zolang het maar werkt en daarna ga ik nog wel leren netter proggen.

Hier nog de oplossing voor als mensen intressen hebben.

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php

function rcopy($itempath,$lastupdate,$updated)
    {
        // gives back the real patch name
        $theitem = realpath($itempath);
        // if $theitem is a real dir then it returns True and goes on
        if(is_dir($theitem)) 
            {
                // gives something back that readdir can use
                $dirhandle = opendir($theitem);

            // will start a loop that will read the dir and places all the elements in an array named $files        
            while(false !== ($files = readdir($dirhandle)))
                {
                // Will skip " . " and " .. " as files
                if(($files !== ".") && ($files !== ".."))
                    {
                    // checks if the element is a dir
                    if(is_dir("".$theitem."/".$files.""))
                        {
                            $dirdate = filemtime("".$theitem."/".$files."");
                            $dirnames = realpath("".$theitem."/".$files."");
                            if($lastupdate < $dirdate)
                            {
                                $updated[] = $dirnames;
                                //array_push($updated,$dirnames);
                                echo " dir ".$dirnames." $dirdate <BR>";
                            }
                            // if the element is a dir it will give the dir name back to $subdir
                            $subdir = realpath("".$theitem."/".$files."");
                            // and then it will run the script again from the top of the function only with the sub dir name
                            $updated = rcopy($subdir,$lastupdate,$updated);
                        }
                    // if the element wasn't a dir then it will check if it's a file
                    elseif(is_file("".$theitem."/".$files.""))
                        {
                            $filedate = filemtime("".$theitem."/".$files."");
                            $filenames = realpath("".$theitem."/".$files."");
                            if($lastupdate < $filedate)
                            {
                                $updated[] = $filenames;
                                //array_push($updated,$filenames);
                                echo " file ".$filenames." $filedate <BR>";
                            }
                        }
                    }
                }
                //closes the dir
                closedir($dirhandle);
            }
        return $updated;
    }

$updated = array();
$tekopieeren = "sync";
$lastupdate = "1115763029";

$updated1 = rcopy($tekopieeren,$lastupdate,$updated);

?>
<PRE>
<?
print_r($updated1);
?>
</PRE>
<?
?>
Pagina: 1