Upload script

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Alain

alain

03/03/2006 16:20:00
Quote Anchor link
Hoi iedereen, Hier ben ik weer maar eens met een vraagje.
Ik heb een upload script op onze website staan, maar na het downloaden van een bestand is het bestand onleesbaar, weet iemand raad ?

http://www.scoutsdonk.be/project/index.php

naam = naam1
wachtwoord= wachtwoord1

Alvast bedankt iedereen

Alain

Hier het script, wel vrij lang :

Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?
if(isset($_GET['download'])){
$file = 'files/'.$_GET['download'];
$filename = $_GET['download'];
header("Content-type: Application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
readfile($file);
ob_end_flush();
}

else{


ob_start();

//namen van personen
$naam = array('naam1','naam2');
//wachtwoorden die bij de personen horen
$wachtwoord = array('wachtwoord1','wachtwoord2');

//toegestane extenties (voor uploaden)
$toegestaan = array(
'ppb',
'ppt',
'mdb',
'rtf',
'doc',
'xls',
'xlb',
'jpg',
'jpeg',
'gif',
'txt',
'html',
'htm');

//soort bestand bij de extenties
$extentienaam = array(
'powerpoint bestand',
'powerpoint bestand',
'access bestand',
'word document',
'word document',
'excel bestand',
'excel bestand',
'afbeelding',
'afbeelding',
'afbeelding',
'kladblok bestand',
'html site',
'html site');




?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Project Sharepoint</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<h2><center>
UPLOADEN
</center></h2>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
if(isset($_GET['files'])){
    echo '<center>>><a href="'.$_SERVER['PHP_SELF'].'">berichten</a><<</center><br><br>';
}

else{
    echo '<center>>><a href="'.$_SERVER['PHP_SELF'].'?files">fileshare</a><<</center><br><br>';
}

if(isset($_GET['uitloggen'])){
    setcookie("project", $_POST['naam'].';'.$_POST['wachtwoord'], time()-604800);
    if(isset($_GET['files'])){
        echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files"</SCRIPT>';
    }

    else{
        echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'"</SCRIPT>';
    }
}

function
inloggen(){
    ?>

Inloggen:
<form method="post" action="
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
<?
    echo $_SERVER['PHP_SELF'];
    if(isset($_GET['files'])){
        echo '?files';
    }

    ?>

">
<input type="hidden" name="inloggen" value="yes">
<fieldset>
<table>

<tr>
<td width="150">naam: <td><input type="tekst" name="naam" border="0">
<tr>
<td>wachtwoord: <td><input type="password" name="wachtwoord" border="0">
<tr>
<td>onthou mij: <td><input type="checkbox" name="onthou" value="ja">
</table>
</fieldset>
<br>
<input type="submit" value="log in" >

</form>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
}

function
inlogfout(){

    echo '<font color="#FF0000">- inloggegevens onjuist -</font><br>';
    inloggen();

}

function
plaats(){
        if(isset($_POST['edit'])){
        $data = '';
        $file = 'berichten.txt';
        $fopenr = fopen($file,'r');
        $berichten = fread ($fopenr, filesize($file));
        fclose($fopenr);
        $bericht = explode('|',$berichten);
        $berichtena = count($bericht);

        $berichtje = htmlentities($_POST['bericht']);
        $berichtje = nl2br($berichtje);
        $berichtje = stripslashes($berichtje);
        $berichtje = str_replace('|','&brvbar;',$berichtje);
        $berichtje = str_replace('^','&circ;',$berichtje);
        for($a='0';$a<$berichtena;$a++){
            if($a == $_POST['edit']){
                $tekst = explode('^',$bericht[$a]);
                $datum = date("d.m.y H:i");
                $data .= $tekst['0'].'^'.$datum.' (edit datum)^'.$berichtje;
            }

            else{
                $data .= $bericht[$a];
            }

            if($a<($berichtena-'1')){
                $data .= '|';
            }
        }


        $fopenw = fopen($file, "w+");
        fwrite($fopenw,$data);
        fclose($fopenw);

    }

    else{
        $naam = $_POST['naam'];
        $bericht = $_POST['bericht'];
        $bericht = htmlentities($bericht);
        $bericht = nl2br($bericht);
        $bericht = stripslashes($bericht);
        $bericht = str_replace('|','&brvbar;',$bericht);
        $bericht = str_replace('^','&circ;',$bericht);


        $file = 'berichten.txt';
        $datum = date("d.m.y H:i");
        $fopenr = fopen($file,'r');
        $berichten = fread ($fopenr, filesize($file));
        fclose($fopenr);
        $berichten .= '|'.$naam.'^'.$datum.'^'.$bericht;
        $fopenw = fopen($file, "w+");
        fwrite($fopenw,$berichten);
        fclose($fopenw);
    }



    echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'"</SCRIPT>';

}

function
edit($nr,$ingelogt){

    $file = 'berichten.txt';
    $fopenr = fopen($file,'r');
    $berichten = fread ($fopenr, filesize($file));
    fclose($fopenr);
    $berichten = str_replace('<br />','',$berichten);
    $bericht = explode('|',$berichten);
    $bericht = explode('^',$bericht[$nr]);
    if($ingelogt == 'nee'){$disabled = 'disabled';}
    elseif($ingelogt == 'ja'){$disabled = '';}
    else{$disabled = 'disabled';}
    echo '<center>edit bericht</center>';
    echo '<fieldset><form action="'.$_SERVER['PHP_SELF'].'?plaats" method="post"><center><textarea '.$disabled.' cols=70 rows=10 name="bericht">'.$bericht['2'].'</textarea></center>';
    echo '<input type="hidden" name="edit" value="'.$nr.'">';
    echo '<br><input type="submit" '.$disabled.' value="edit bericht"></form></fieldset>';

}

function
berichten($ingelogt,$naam){

    //delete een bericht
    if(($ingelogt == 'ja') && (isset($_GET['delete']))){
        $nr = $_GET['delete'];
        $data = '';
        $file = 'berichten.txt';
        $fopenr = fopen($file,'r');
        $berichten = fread ($fopenr, filesize($file));
        fclose($fopenr);
        $bericht = explode('|',$berichten);
        $berichtena = count($bericht);

        for($a='0';$a<$berichtena;$a++){
            if($a != $nr){

                $data .= $bericht[$a];
                if($a<($berichtena-'1')){
                    if(  ($a == $nr-'1') && ($nr == $berichtena-'1') ){}
                    else{
                    $data .= '|';
                    }
                }
            }
        }


        $fopenw = fopen($file, "w+");
        fwrite($fopenw,$data);
        fclose($fopenw);
        echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'"</SCRIPT>';
    }

    //als ingelogt is:
    if($ingelogt == 'ja'){
        if(isset($_GET['plaats'])){
            plaats();
        }

        echo 'ingelogt als: <b>'.$naam.'</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="'.$_SERVER['PHP_SELF'].'?uitloggen=ja">uitloggen</a><br><br>';
    }


    $file = 'berichten.txt';
    $fopenr = fopen($file,'r');
    $berichten = fread ($fopenr, filesize($file));
    fclose($fopenr);
    $bericht = explode('|',$berichten);
    $berichtena = count($bericht);

    if(isset($_GET['edit'])){
        edit($_GET['nr'],$ingelogt);
    }

    else{

        for($i='0';$i < $berichtena;$i++){
            $data = explode('^',$bericht[$i]);
            echo '<fieldset><b><strong>'.$data['0'].'</b></strong> schreef op <i>'.$data['1'].'</i>';
            if($naam == $data['0']){
                echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?edit=ja&nr='.$i.'">edit</a>|<a href="'.$_SERVER['PHP_SELF'].'?delete='.$i.'">delete</a>';
            }

            echo '<br><br>'.$data['2'].'</fieldset><br>';
        }

        if($ingelogt == 'nee'){$disabled = 'disabled';}
        elseif($ingelogt == 'ja'){$disabled = '';}
        else{$disabled = 'disabled';}
        echo '<fieldset><form action="'.$_SERVER['PHP_SELF'].'?plaats" method="post"><center><textarea '.$disabled.' cols=70 rows=10 name="bericht"></textarea></center>';
        echo '<input type="hidden" name="naam" value="'.$naam.'">';
        echo '<br><input type="submit" '.$disabled.' value="plaats bericht"></form></fieldset>';
    }

}



function
files($ingelogt,$naam,$toegestaan,$extensienaam){

    if($ingelogt == 'ja'){
        echo 'ingelogt als: <b>'.$naam.'</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="'.$_SERVER['PHP_SELF'].'?uitloggen=ja&files">uitloggen</a><br><br>';
    }

    //$file = $_FILES['file']['name'] of ['size']
    //unlink(filename) //delete
    //if(is_uploaded_file($_FILES['file']['tmp_name'])){//checken of het via http post is gedaan
        //move_uploaded_file($_FILES['file']['tmp_name'],'files/'.$uploadname) //verplaatsen


    if((!isset($_GET['download'])) && (!isset($_GET['delete'])) && (!isset($_POST['upload']))){
        if(isset($_GET['fout'])){
            echo '<font color="#FF0000"> - uploaden mislukt - </font><br>';
        }

        if(isset($_GET['extentiefout'])){
            echo '<font color="#FF0000"> - dit filetype mag niet geupload worden - </font><br>';
        }

        $toegestaana = count($toegestaan);
        $handle = opendir('files');
        $nr = '0';
        while (false!==($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $files[$nr] = $file;
                $nr++;
            }
        }


        sort($files);
        $aantal = count($files);
        echo '<fieldset><table><tr><td width="150">bestands naam: <br><br><td width="150">bestands type: <br><br><td width="225">datum <br><br><td width="150">grootte:<br><br>';
        for($a = '0';$a < $aantal;$a++){
            $extentie = explode('.',$files[$a]);
            for($b='0';$b<$toegestaana;$b++){
                if($extentie['1'] == $toegestaan[$b]){
                    $filetype = $extensienaam[$b];
                    break;
                }
            }

            $filesize = filesize('files/'.$files[$a]);
            $filesize = ($filesize/'1000');
            $filesize = round($filesize);
            echo '<tr><td>-<b> '.$extentie['0'].'</b>.'.$extentie['1'].'<br><td> '.$filetype.'<td> '.date("d F Y - H:i:s",filectime('files/'.$files[$a])).'<td>'.$filesize.'kb';
            if($ingelogt == 'ja'){
                echo '<td><a href="'.$_SERVER['PHP_SELF'].'?files&download='.$files[$a].'">download</a> | <a href="'.$_SERVER['PHP_SELF'].'?files&delete='.$files[$a].'">delete</a>';
            }

        }

        echo '</table></fieldset><br>';
        closedir($handle);
        if($ingelogt=='ja'){
            echo '<fieldset>upload file:<table><form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?files"><input type="hidden" value="upload" name="upload"><tr><td>bestand:<td><input type="file" name="file"><br>';
            echo '<tr><td>nieuwe naam gebruiken:<td><input type="checkbox" value="ja" name="gebruiknaam">';
            echo '<br><tr><td>nieuwe naam (optioneel):<td><input type="text" name="nieuwenaam"></table><br><br><input type="submit" value="upload file"></fieldset>';
        }

    }

    else{

        if(isset($_POST['upload'])){
            upload($toegestaan);
        }


        elseif(isset($_GET['delete'])){
            unlink('files/'.$_GET['delete']);
            echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files"</SCRIPT>';
        }
    }

}

function
upload($allow){

    global $_FILES;
    if(isset($_FILES['file'])){
        $file = $_FILES['file']['name'];
        $size = $_FILES['file']['size'];
        if(isset($_POST['gebruiknaam'])){
            $filename = $_POST['nieuwenaam'];
        }

        else{
            $filename = explode('.',$_FILES['file']['name']);
            $filename = $filename['0'];
        }

        $extentie = explode('.',$file);
        $extentie = $extentie['1'];

        $allowa = count($allow);
        for($a='0';$a < $allowa;$a++){
            if($extentie == $allow[$a]){
                $extentiecheck = 'oke';
                break;
            }

            else{
                $extentiecheck = 'nietoke';
            }
        }


        if($extentiecheck == 'oke'){
            if(is_uploaded_file($_FILES['file']['tmp_name'])){
                move_uploaded_file($_FILES['file']['tmp_name'],'files/'.$filename.'.'.$extentie);
                echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files"</SCRIPT>';
            }

            else{
                echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files&fout"</SCRIPT>';
            }
        }

        else{
            echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files&extentiefout"</SCRIPT>';
        }
    }
}

//inloggen






$aantal = count($naam);

if(isset($_COOKIE['project'])){
    $cookie = explode(';',$_COOKIE['project']);
    for($a='0';$a<$aantal;$a++){
        if(($cookie['0'] == $naam[$a]) && ($cookie['1'] == $wachtwoord[$a])){
            if(isset($_GET['files'])){
                files('ja',$cookie['0'],$toegestaan,$extentienaam);
            }

            else{
                berichten('ja',$cookie['0']);
            }

            break;
        }

        elseif( (($cookie['0'] !== $naam[$a]) && ($cookie['1'] !== $wachtwoord[$a])) && ($a == ($aantal-'1'))) {
            inlogfout();
            if(isset($_GET['files'])){
                files('nee','',$toegestaan,$extentienaam);
            }

            else{
                berichten('nee','');
            }
        }
    }
}

else{
    if(isset($_POST['inloggen'])){
        if($_POST['inloggen'] == 'yes'){
            for($a='0';$a<$aantal;$a++){
                if($_POST['naam'] == $naam[$a]){
                    if($_POST['wachtwoord'] == $wachtwoord[$a]){
                        if(isset($_GET['files'])){
                            files('ja',$_POST['naam'],$toegestaan,$extentienaam);
                        }

                        else{
                            berichten('ja',$_POST['naam']);
                        }

                        if(isset($_POST['onthou'])){
                            setcookie("project", $_POST['naam'].';'.$_POST['wachtwoord'], time()+604800);
                            ob_end_flush();
                        }

                        else{
                            setcookie("project", $_POST['naam'].';'.$_POST['wachtwoord'], time()+600);
                        }

                        break;
                    }

                    else{
                        inlogfout();
                        if(isset($_GET['files'])){
                            files('nee','',$toegestaan,$extentienaam);
                        }

                        else{
                            berichten('nee','');
                        }

                        break;
                    }
                }

                elseif(($_POST['naam'] !== $naam[$a]) && ($a == ($aantal-'1'))) {
                    inlogfout();
                    if(isset($_GET['files'])){
                        files('nee','',$toegestaan,$extentienaam);
                    }

                    else{
                        berichten('nee','');
                    }
                }
            }
        }

        else{
            inloggen();
            if(isset($_GET['files'])){
                files('nee','',$toegestaan,$extentienaam);
            }

            else{
                berichten('nee','');
            }
        }
    }

    else{
        inloggen();
        if(isset($_GET['files'])){
            files('nee','',$toegestaan,$extentienaam);
        }

        else{
            berichten('nee','');
        }
    }
}



?>


</body>
</html>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?
}//voor de download else
?>
 
PHP hulp

PHP hulp

23/09/2021 13:36:15
 

03/03/2006 16:23:00
Quote Anchor link
je zei dat het onleesbaar was, maar wat krijg je dan te zien? Doe anders ff een klein stukje voorbeeld, bijv 3 regels

kun je btw ff alle html uit je code halen hier op het forum, dan is je bericht zoveel korter:P


edit: dit is het sharepoint wat op deze site staat!
Gewijzigd op 03/03/2006 16:25:00 door
 
Alain

alain

03/03/2006 16:34:00
Quote Anchor link
na het openen van een gedownload document op de pc is het totaal onleesbaar:

ÐÏ à¡± á > þÿ
þÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

het script zonder html:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?
if(isset($_GET['download'])){
$file = 'files/'.$_GET['download'];
$filename = $_GET['download'];
header("Content-type: Application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
readfile($file);
ob_end_flush();
}

else{


ob_start();

//namen van personen
$naam = array('naam1','naam2');
//wachtwoorden die bij de personen horen
$wachtwoord = array('wachtwoord1','wachtwoord2');

//toegestane extenties (voor uploaden)
$toegestaan = array(
'ppb',
'ppt',
'mdb',
'rtf',
'doc',
'xls',
'xlb',
'jpg',
'jpeg',
'gif',
'txt',
'html',
'htm');

//soort bestand bij de extenties
$extentienaam = array(
'powerpoint bestand',
'powerpoint bestand',
'access bestand',
'word document',
'word document',
'excel bestand',
'excel bestand',
'afbeelding',
'afbeelding',
'afbeelding',
'kladblok bestand',
'html site',
'html site');
?>

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
if(isset($_GET['files'])){
    echo '<center>>><a href="'.$_SERVER['PHP_SELF'].'">berichten</a><<</center><br><br>';
}

else{
    echo '<center>>><a href="'.$_SERVER['PHP_SELF'].'?files">fileshare</a><<</center><br><br>';
}

if(isset($_GET['uitloggen'])){
    setcookie("project", $_POST['naam'].';'.$_POST['wachtwoord'], time()-604800);
    if(isset($_GET['files'])){
        echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files"</SCRIPT>';
    }

    else{
        echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'"</SCRIPT>';
    }
}

function
inloggen(){
    ?>

Inloggen:
<form method="post" action="
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
<?
    echo $_SERVER['PHP_SELF'];
    if(isset($_GET['files'])){
        echo '?files';
    }

    ?>


Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
}

function
inlogfout(){

    echo '<font color="#FF0000">- inloggegevens onjuist -</font><br>';
    inloggen();

}

function
plaats(){
        if(isset($_POST['edit'])){
        $data = '';
        $file = 'berichten.txt';
        $fopenr = fopen($file,'r');
        $berichten = fread ($fopenr, filesize($file));
        fclose($fopenr);
        $bericht = explode('|',$berichten);
        $berichtena = count($bericht);

        $berichtje = htmlentities($_POST['bericht']);
        $berichtje = nl2br($berichtje);
        $berichtje = stripslashes($berichtje);
        $berichtje = str_replace('|','&brvbar;',$berichtje);
        $berichtje = str_replace('^','&circ;',$berichtje);
        for($a='0';$a<$berichtena;$a++){
            if($a == $_POST['edit']){
                $tekst = explode('^',$bericht[$a]);
                $datum = date("d.m.y H:i");
                $data .= $tekst['0'].'^'.$datum.' (edit datum)^'.$berichtje;
            }

            else{
                $data .= $bericht[$a];
            }

            if($a<($berichtena-'1')){
                $data .= '|';
            }
        }


        $fopenw = fopen($file, "w+");
        fwrite($fopenw,$data);
        fclose($fopenw);

    }

    else{
        $naam = $_POST['naam'];
        $bericht = $_POST['bericht'];
        $bericht = htmlentities($bericht);
        $bericht = nl2br($bericht);
        $bericht = stripslashes($bericht);
        $bericht = str_replace('|','&brvbar;',$bericht);
        $bericht = str_replace('^','&circ;',$bericht);


        $file = 'berichten.txt';
        $datum = date("d.m.y H:i");
        $fopenr = fopen($file,'r');
        $berichten = fread ($fopenr, filesize($file));
        fclose($fopenr);
        $berichten .= '|'.$naam.'^'.$datum.'^'.$bericht;
        $fopenw = fopen($file, "w+");
        fwrite($fopenw,$berichten);
        fclose($fopenw);
    }



    echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'"</SCRIPT>';

}

function
edit($nr,$ingelogt){

    $file = 'berichten.txt';
    $fopenr = fopen($file,'r');
    $berichten = fread ($fopenr, filesize($file));
    fclose($fopenr);
    $berichten = str_replace('<br />','',$berichten);
    $bericht = explode('|',$berichten);
    $bericht = explode('^',$bericht[$nr]);
    if($ingelogt == 'nee'){$disabled = 'disabled';}
    elseif($ingelogt == 'ja'){$disabled = '';}
    else{$disabled = 'disabled';}
    echo '<center>edit bericht</center>';
    echo '<fieldset><form action="'.$_SERVER['PHP_SELF'].'?plaats" method="post"><center><textarea '.$disabled.' cols=70 rows=10 name="bericht">'.$bericht['2'].'</textarea></center>';
    echo '<input type="hidden" name="edit" value="'.$nr.'">';
    echo '<br><input type="submit" '.$disabled.' value="edit bericht"></form></fieldset>';

}

function
berichten($ingelogt,$naam){

    //delete een bericht
    if(($ingelogt == 'ja') && (isset($_GET['delete']))){
        $nr = $_GET['delete'];
        $data = '';
        $file = 'berichten.txt';
        $fopenr = fopen($file,'r');
        $berichten = fread ($fopenr, filesize($file));
        fclose($fopenr);
        $bericht = explode('|',$berichten);
        $berichtena = count($bericht);

        for($a='0';$a<$berichtena;$a++){
            if($a != $nr){

                $data .= $bericht[$a];
                if($a<($berichtena-'1')){
                    if(  ($a == $nr-'1') && ($nr == $berichtena-'1') ){}
                    else{
                    $data .= '|';
                    }
                }
            }
        }


        $fopenw = fopen($file, "w+");
        fwrite($fopenw,$data);
        fclose($fopenw);
        echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'"</SCRIPT>';
    }

    //als ingelogt is:
    if($ingelogt == 'ja'){
        if(isset($_GET['plaats'])){
            plaats();
        }

        echo 'ingelogt als: <b>'.$naam.'</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="'.$_SERVER['PHP_SELF'].'?uitloggen=ja">uitloggen</a><br><br>';
    }


    $file = 'berichten.txt';
    $fopenr = fopen($file,'r');
    $berichten = fread ($fopenr, filesize($file));
    fclose($fopenr);
    $bericht = explode('|',$berichten);
    $berichtena = count($bericht);

    if(isset($_GET['edit'])){
        edit($_GET['nr'],$ingelogt);
    }

    else{

        for($i='0';$i < $berichtena;$i++){
            $data = explode('^',$bericht[$i]);
            echo '<fieldset><b><strong>'.$data['0'].'</b></strong> schreef op <i>'.$data['1'].'</i>';
            if($naam == $data['0']){
                echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.$_SERVER['PHP_SELF'].'?edit=ja&nr='.$i.'">edit</a>|<a href="'.$_SERVER['PHP_SELF'].'?delete='.$i.'">delete</a>';
            }

            echo '<br><br>'.$data['2'].'</fieldset><br>';
        }

        if($ingelogt == 'nee'){$disabled = 'disabled';}
        elseif($ingelogt == 'ja'){$disabled = '';}
        else{$disabled = 'disabled';}
        echo '<fieldset><form action="'.$_SERVER['PHP_SELF'].'?plaats" method="post"><center><textarea '.$disabled.' cols=70 rows=10 name="bericht"></textarea></center>';
        echo '<input type="hidden" name="naam" value="'.$naam.'">';
        echo '<br><input type="submit" '.$disabled.' value="plaats bericht"></form></fieldset>';
    }

}



function
files($ingelogt,$naam,$toegestaan,$extensienaam){

    if($ingelogt == 'ja'){
        echo 'ingelogt als: <b>'.$naam.'</b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="'.$_SERVER['PHP_SELF'].'?uitloggen=ja&files">uitloggen</a><br><br>';
    }

    //$file = $_FILES['file']['name'] of ['size']
    //unlink(filename) //delete
    //if(is_uploaded_file($_FILES['file']['tmp_name'])){//checken of het via http post is gedaan
        //move_uploaded_file($_FILES['file']['tmp_name'],'files/'.$uploadname) //verplaatsen


    if((!isset($_GET['download'])) && (!isset($_GET['delete'])) && (!isset($_POST['upload']))){
        if(isset($_GET['fout'])){
            echo '<font color="#FF0000"> - uploaden mislukt - </font><br>';
        }

        if(isset($_GET['extentiefout'])){
            echo '<font color="#FF0000"> - dit filetype mag niet geupload worden - </font><br>';
        }

        $toegestaana = count($toegestaan);
        $handle = opendir('files');
        $nr = '0';
        while (false!==($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $files[$nr] = $file;
                $nr++;
            }
        }


        sort($files);
        $aantal = count($files);
        echo '<fieldset><table><tr><td width="150">bestands naam: <br><br><td width="150">bestands type: <br><br><td width="225">datum <br><br><td width="150">grootte:<br><br>';
        for($a = '0';$a < $aantal;$a++){
            $extentie = explode('.',$files[$a]);
            for($b='0';$b<$toegestaana;$b++){
                if($extentie['1'] == $toegestaan[$b]){
                    $filetype = $extensienaam[$b];
                    break;
                }
            }

            $filesize = filesize('files/'.$files[$a]);
            $filesize = ($filesize/'1000');
            $filesize = round($filesize);
            echo '<tr><td>-<b> '.$extentie['0'].'</b>.'.$extentie['1'].'<br><td> '.$filetype.'<td> '.date("d F Y - H:i:s",filectime('files/'.$files[$a])).'<td>'.$filesize.'kb';
            if($ingelogt == 'ja'){
                echo '<td><a href="'.$_SERVER['PHP_SELF'].'?files&download='.$files[$a].'">download</a> | <a href="'.$_SERVER['PHP_SELF'].'?files&delete='.$files[$a].'">delete</a>';
            }

        }

        echo '</table></fieldset><br>';
        closedir($handle);
        if($ingelogt=='ja'){
            echo '<fieldset>upload file:<table><form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'?files"><input type="hidden" value="upload" name="upload"><tr><td>bestand:<td><input type="file" name="file"><br>';
            echo '<tr><td>nieuwe naam gebruiken:<td><input type="checkbox" value="ja" name="gebruiknaam">';
            echo '<br><tr><td>nieuwe naam (optioneel):<td><input type="text" name="nieuwenaam"></table><br><br><input type="submit" value="upload file"></fieldset>';
        }

    }

    else{

        if(isset($_POST['upload'])){
            upload($toegestaan);
        }


        elseif(isset($_GET['delete'])){
            unlink('files/'.$_GET['delete']);
            echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files"</SCRIPT>';
        }
    }

}

function
upload($allow){

    global $_FILES;
    if(isset($_FILES['file'])){
        $file = $_FILES['file']['name'];
        $size = $_FILES['file']['size'];
        if(isset($_POST['gebruiknaam'])){
            $filename = $_POST['nieuwenaam'];
        }

        else{
            $filename = explode('.',$_FILES['file']['name']);
            $filename = $filename['0'];
        }

        $extentie = explode('.',$file);
        $extentie = $extentie['1'];

        $allowa = count($allow);
        for($a='0';$a < $allowa;$a++){
            if($extentie == $allow[$a]){
                $extentiecheck = 'oke';
                break;
            }

            else{
                $extentiecheck = 'nietoke';
            }
        }


        if($extentiecheck == 'oke'){
            if(is_uploaded_file($_FILES['file']['tmp_name'])){
                move_uploaded_file($_FILES['file']['tmp_name'],'files/'.$filename.'.'.$extentie);
                echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files"</SCRIPT>';
            }

            else{
                echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files&fout"</SCRIPT>';
            }
        }

        else{
            echo '<SCRIPT LANGUAGE="javascript" TYPE="text/javascript">window.location="'.$_SERVER['PHP_SELF'].'?files&extentiefout"</SCRIPT>';
        }
    }
}

//inloggen






$aantal = count($naam);

if(isset($_COOKIE['project'])){
    $cookie = explode(';',$_COOKIE['project']);
    for($a='0';$a<$aantal;$a++){
        if(($cookie['0'] == $naam[$a]) && ($cookie['1'] == $wachtwoord[$a])){
            if(isset($_GET['files'])){
                files('ja',$cookie['0'],$toegestaan,$extentienaam);
            }

            else{
                berichten('ja',$cookie['0']);
            }

            break;
        }

        elseif( (($cookie['0'] !== $naam[$a]) && ($cookie['1'] !== $wachtwoord[$a])) && ($a == ($aantal-'1'))) {
            inlogfout();
            if(isset($_GET['files'])){
                files('nee','',$toegestaan,$extentienaam);
            }

            else{
                berichten('nee','');
            }
        }
    }
}

else{
    if(isset($_POST['inloggen'])){
        if($_POST['inloggen'] == 'yes'){
            for($a='0';$a<$aantal;$a++){
                if($_POST['naam'] == $naam[$a]){
                    if($_POST['wachtwoord'] == $wachtwoord[$a]){
                        if(isset($_GET['files'])){
                            files('ja',$_POST['naam'],$toegestaan,$extentienaam);
                        }

                        else{
                            berichten('ja',$_POST['naam']);
                        }

                        if(isset($_POST['onthou'])){
                            setcookie("project", $_POST['naam'].';'.$_POST['wachtwoord'], time()+604800);
                            ob_end_flush();
                        }

                        else{
                            setcookie("project", $_POST['naam'].';'.$_POST['wachtwoord'], time()+600);
                        }

                        break;
                    }

                    else{
                        inlogfout();
                        if(isset($_GET['files'])){
                            files('nee','',$toegestaan,$extentienaam);
                        }

                        else{
                            berichten('nee','');
                        }

                        break;
                    }
                }

                elseif(($_POST['naam'] !== $naam[$a]) && ($a == ($aantal-'1'))) {
                    inlogfout();
                    if(isset($_GET['files'])){
                        files('nee','',$toegestaan,$extentienaam);
                    }

                    else{
                        berichten('nee','');
                    }
                }
            }
        }

        else{
            inloggen();
            if(isset($_GET['files'])){
                files('nee','',$toegestaan,$extentienaam);
            }

            else{
                berichten('nee','');
            }
        }
    }

    else{
        inloggen();
        if(isset($_GET['files'])){
            files('nee','',$toegestaan,$extentienaam);
        }

        else{
            berichten('nee','');
        }
    }
}

?>


Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?
}//voor de download else
?>
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.