Ik heb op mijn website een script dat een bestand aanmaakt en in dit bestand staat dan een tekst.
Nou moet er op de hoofdpagina automatisch een link komen naar dit bestandje.
Als er geen tekst word toegevoegd in word het bestand ook niet aangemaakt en dat klopt.
Alleen nu moet de link naar het bestandje ook niet verschijnen als het bestand niet bestaat.
Nu controleer ik of het bestand bestaat met deze code:
Alleen dit werkt niet.
Als ik bij if(file_exists("pad/naar/".$naam."-".$bericht.".txt")) het voledige pad geef dus bijvoorbeeld pad/naar/naam-bericht.txt dan werkt het wel en verschijnt er overal een link.
Nou zit het probleem denk ik in de variabellen maar op wat voor manier ik die er ook neerzet het blijft fout gaan.
Wat doe ik fout?
Ik heb deze 2 bestanden
audio.php
schrijf_audio.php
Nou moet er op de hoofdpagina automatisch een link komen naar dit bestandje.
Als er geen tekst word toegevoegd in word het bestand ook niet aangemaakt en dat klopt.
Alleen nu moet de link naar het bestandje ook niet verschijnen als het bestand niet bestaat.
Nu controleer ik of het bestand bestaat met deze code:
PHP:
1
2
3
4
5
6
7
8
| if(file_exists("pad/naar/".$naam."-".$bericht.".txt")) { print"<p>$naam<br /><a href='http://$url'>$bericht</a><br /><a href='admin/tracklist/$naam-$bericht.txt' target='_blank'>Tracklist</a><hr color='#FF6633' /></p>"; } else { print"<p>$naam<br /><a href='http://$url'>$bericht</a><br /><hr color='#FF6633' /></p>"; }} |
Alleen dit werkt niet.
Als ik bij if(file_exists("pad/naar/".$naam."-".$bericht.".txt")) het voledige pad geef dus bijvoorbeeld pad/naar/naam-bericht.txt dan werkt het wel en verschijnt er overal een link.
Nou zit het probleem denk ik in de variabellen maar op wat voor manier ik die er ook neerzet het blijft fout gaan.
Wat doe ik fout?
Ik heb deze 2 bestanden
audio.php
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
| <? echo"<p class='contenttitle'>A U D I O</p>"; $bestand=array_reverse(file("admin/audio.txt")); echo ($bestand) ? "" : "<h3>There isn't audio posted yet!</h3>"; foreach($bestand as $i) { $i=explode("|",$i); $naam = $i[0]; $url = $i[1]; $bericht = $i[2]; $url = htmlspecialchars($url); $naam = htmlspecialchars($naam); $bericht = htmlspecialchars($bericht); $bericht = str_replace("<br>","<br>",$bericht); if(file_exists('admin/tracklist/$naam-$bericht.txt')) { print"<p>$naam<br /><a href='http://$url'>$bericht</a><br /><a href='admin/tracklist/$naam-$bericht.txt' target='_blank'>Tracklist</a><hr color='#FF6633' /></p>"; } else { print"<p>$naam<br /><a href='http://$url'>$bericht</a><br /><hr color='#FF6633' /></p>"; }} ?> |
schrijf_audio.php
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
| <?php include('inc/head.php'); if(!$tracklist) { $datum = date("d-m-Y"); if($naam && $url && $bericht) { $bestand = fopen("audio.txt", "a"); $bericht = str_replace("\n","<br />",$bericht); $bericht = str_replace("|","",$bericht); $naam = str_replace("|","",$naam); $url = str_replace("|","",$url); fwrite($bestand, "$naam|$url|$bericht\n"); fclose($bestand); echo"De MP3 is toegevoegd!"; } else { echo"<form method=post action=$PHP_SELF>"; echo"Artiest(en):<br><input type=text name=naam> (bijv. Tactix ft. REN51)<br />"; echo"URL:<br><input type=text name=url>(zonder http://)<br>"; echo"Beschrijving:<br><textarea cols=30 rows=10 name=bericht></textarea>(bijv. Live @ Reaktor 24-09-2005)<br />"; echo"Tracklist:<br><textarea cols=30 rows=10 name=tracklist></textarea>"; echo"<input type=submit value='Verstuur'>"; echo"</form>"; } include('inc/foot.php'); } else { if(!function_exists('file_put_contents')) { function file_put_contents($filename, $data, $file_append = false) { $fp = fopen($filename, (!$file_append ? 'w+' : 'a+')); if(!$fp) { trigger_error('file_put_contents cannot write in file.', E_USER_ERROR); return; } fputs($fp, $data); fclose($fp); } } file_put_contents("tracklist/$bericht .txt", "$tracklist"); $datum = date("d-m-Y"); if($naam && $url && $bericht) { $bestand = fopen("audio.txt", "a"); $bericht = str_replace("\n","<br />",$bericht); $bericht = str_replace("|","",$bericht); $naam = str_replace("|","",$naam); $url = str_replace("|","",$url); fwrite($bestand, "$naam|$url|$bericht\n"); fclose($bestand); echo"De MP3 is toegevoegd!"; } else { echo"<form method=post action=$PHP_SELF>"; echo"Artiest(en):<br><input type=text name=naam> (bijv. Tactix ft. REN51)<br />"; echo"URL:<br><input type=text name=url>(zonder http://)<br>"; echo"Beschrijving:<br><textarea cols=30 rows=10 name=bericht></textarea>(bijv. Live @ Reaktor 24-09-2005)<br />"; echo"Tracklist:<br><textarea cols=30 rows=10 name=tracklist></textarea>"; echo"<input type=submit value='Verstuur'>"; echo"</form>"; } include('inc/foot.php'); } ?> |