php bestand verwijderen uit directory

Gestart doorThijmgrijs27 reacties43 weergaven

28 berichten · pagina 1 van 2

Thijmgrijs

Lid · Topicstarter

Berichten
968
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo Allemaal,

Ik ben bezig met een upload & weergave script voor mezelf alleen kom ik er niet helemaal uit met de verwijder functie.
Hieronder mn script op dit moment en uitgelegt wat erbij moet.

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

$files = glob(uploads/*.*);

if (is_array($files) and count($files)) {
echo
;
foreach ($files as $file) {
echo
. basename($file) .
- .
$file . ">Download
;
}

echo ;
}

else {
echo

Er zijn geen bestanden gevonden

;
}


?>

Maar ik wil dus dat er achter de download komt te staan:
BESTAND.zip - Download / Verwijder (Dus 2 opties, downloaden en verwijderen)

Quote:
Momenteel heb ik dit dus:

One2xs.zip - Download
En graag wil ik het zo:

One2xs.zip - Download / Verwijder

Beloning voor het werkende maken = 0,5 punt

Mvg,

Thijmen
0
Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
ftp_delete?
0
Thijmgrijs

Lid · Topicstarter

Berichten
968
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Dylanh schreef:
ftp_delete?
Ja dat die door de functie verwijder het bestand uit de map bij mij /uploads/ verwijderd.
Alleen dat bestand, dus niet alle bestanden!
0
Thijmgrijs

Lid · Topicstarter

Berichten
968
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
http://nl3.php.net/ftp_delete
De eerste example...
Dat is het dus niet,

Ik kan dit zelf ook wel bedenken:

$bestand= "TEST.txt";
unlink($bestand);


Maar het inbouwen ervan in dat script, en dat het er mooi achter komt te staan.
Dus zoals:

One2xs.zip - Download / Verwijder

Dat door dat ik op verwijder klik het op de zelfde pagina verwijderd word vanaf mn ftp.
En niet dat ik door middel van een andere pagina een redirect krijg.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Even uit mijn hoofd (hoeft dus niet 100% correct te werken, het is een voorbeeld!):

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]act[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]del[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]file[/COLOR][COLOR= #007700]])
    {[/COLOR]
        [URL="http://www.php.net/unlink"]unlink[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]file[/COLOR][COLOR= #007700]]);
    }
}[/COLOR]

[COLOR= #0000BB]$files[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/glob"]glob[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/*.*[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR][COLOR= #007700])[/COLOR] and [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR][COLOR= #007700])) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<table>[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) {[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<tr>
        <td>[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/basename"]basename[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]</td>
        <td> - <a href="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$file[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]">Download</a> / <a href="?act=del&amp;file=[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$file[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]">Verwijder</a></td>
      </tr>[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</table>[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<p>Er zijn geen bestanden gevonden</p>[/COLOR][COLOR= #007700];
}[/COLOR]

?>


Zo moeilijk lijkt me dit toch niet, dit is basisphp.
0
Thijmgrijs

Lid · Topicstarter

Berichten
968
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rik schreef:
Even uit mijn hoofd (hoeft dus niet 100% correct te werken, het is een voorbeeld!):
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]act[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]del[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]file[/COLOR][COLOR= #007700]])
    {[/COLOR]
        [URL="http://www.php.net/unlink"]unlink[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]file[/COLOR][COLOR= #007700]]);
    }
}[/COLOR]

[COLOR= #0000BB]$files[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/glob"]glob[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/*.*[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR][COLOR= #007700])[/COLOR] and [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR][COLOR= #007700])) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<table>[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) {[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<tr>
        <td>[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/basename"]basename[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]</td>
        <td> - <a href="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$file[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]">Download</a> / <a href="?act=del&amp;file=[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$file[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]">Verwijder</a></td>
      </tr>[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</table>[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<p>Er zijn geen bestanden gevonden</p>[/COLOR][COLOR= #007700];
}[/COLOR]

?>


Zo moeilijk lijkt me dit toch niet, dit is basisphp.

Parse error: syntax error, unexpected { in /home/*****/domains/******/public_html/overzicht.php on line 5

Het is inderdaad basisphp.
Maar heb vandaag echt teveel gedaan, ik block mezelf een beetje sadleyMoesten binnen 1 dag een volledig systeem maken en kijken hoever we kwamen, voor mn nieuwe opleiding. Ik ben al klaar ermee eigenlijk, maar dit zijn van die extra dingetjes die erbij kunnen.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Tel je haakjes eens....
En die + moet een punt zijn, het is PHP en geen JS wink
0
Thijmgrijs

Lid · Topicstarter

Berichten
968
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Tel je haakjes eens....
En die + moet een punt zijn, het is PHP en geen JS wink
Thanks,

Ik snap die haakjes niet want die { staat voor if(file_exists(uploads/ + $_GET[file]).
en daar in die functie neemt die {
unlink(uploads/ + $_GET[file]);
} mee door

En dat laatste is volgensmij voor het sluiten van de eerste functie?
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
haakjes zijn ( en )
accolades zijn { en }
0
Thijmgrijs

Lid · Topicstarter

Berichten
968
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sjoerd schreef:
haakjes zijn ( en )
accolades zijn { en }
Ja wist het woord niet emoKan jij het even snel voor me oplossen?
Ik maak je dan 0,3 over.
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat is de foutmelding nu dan?
Haakjes tellen is toch niet zo moeilijk? Regel 4 klopt niet helemaal.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Thijmgrijs schreef:
Eerdere citaten tonen
Rik schreef:
Even uit mijn hoofd (hoeft dus niet 100% correct te werken, het is een voorbeeld!):
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]act[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]del[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]file[/COLOR][COLOR= #007700]])
    {[/COLOR]
        [URL="http://www.php.net/unlink"]unlink[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]file[/COLOR][COLOR= #007700]]);
    }
}[/COLOR]

[COLOR= #0000BB]$files[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/glob"]glob[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/*.*[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR][COLOR= #007700])[/COLOR] and [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR][COLOR= #007700])) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<table>[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) {[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<tr>
        <td>[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/basename"]basename[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]</td>
        <td> - <a href="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$file[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]">Download</a> / <a href="?act=del&amp;file=[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$file[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]">Verwijder</a></td>
      </tr>[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</table>[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<p>Er zijn geen bestanden gevonden</p>[/COLOR][COLOR= #007700];
}[/COLOR]

?>


Zo moeilijk lijkt me dit toch niet, dit is basisphp.
Parse error: syntax error, unexpected { in /home/*****/domains/******/public_html/overzicht.php on line 5

Het is inderdaad basisphp.
Maar heb vandaag echt teveel gedaan, ik block mezelf een beetje sadleyMoesten binnen 1 dag een volledig systeem maken en kijken hoever we kwamen, voor mn nieuwe opleiding. Ik ben al klaar ermee eigenlijk, maar dit zijn van die extra dingetjes die erbij kunnen.

Lezen is latig:

Quote:
(hoeft dus niet 100% correct te werken, het is een voorbeeld!)

Geeft dus weer aan dat je de code gewoon één op één hebt gekopieerd en geen moeite ervoor doet.
Aarclay schreef:
Tel je haakjes eens....
En die + moet een punt zijn, het is PHP en geen JS wink
Sorry, ik zit met school met C# en Java die wel met de "+" werkt in plaats van de "."
0
Thijmgrijs

Lid · Topicstarter

Berichten
968
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rik schreef:
Eerdere citaten tonen
Thijmgrijs schreef:
Eerdere citaten tonen
Rik schreef:
Even uit mijn hoofd (hoeft dus niet 100% correct te werken, het is een voorbeeld!):
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]act[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]del[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/file_exists"]file_exists[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]file[/COLOR][COLOR= #007700]])
    {[/COLOR]
        [URL="http://www.php.net/unlink"]unlink[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/[/COLOR] [COLOR= #007700]+[/COLOR] [COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]file[/COLOR][COLOR= #007700]]);
    }
}[/COLOR]

[COLOR= #0000BB]$files[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/glob"]glob[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]uploads/*.*[/COLOR][COLOR= #007700]);[/COLOR]

[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][URL="http://www.php.net/is_array"]is_array[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR][COLOR= #007700])[/COLOR] and [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR][COLOR= #007700])) {[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<table>[/COLOR][COLOR= #007700];[/COLOR]
    [URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$files[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) {[/COLOR]
      [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<tr>
        <td>[/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/basename"]basename[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$file[/COLOR][COLOR= #007700]) .[/COLOR] [COLOR= #DD0000]</td>
        <td> - <a href="[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$file[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]">Download</a> / <a href="?act=del&amp;file=[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #0000BB]$file[/COLOR] [COLOR= #007700].[/COLOR] [COLOR= #DD0000]">Verwijder</a></td>
      </tr>[/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</table>[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<p>Er zijn geen bestanden gevonden</p>[/COLOR][COLOR= #007700];
}[/COLOR]

?>


Zo moeilijk lijkt me dit toch niet, dit is basisphp.
Parse error: syntax error, unexpected { in /home/*****/domains/******/public_html/overzicht.php on line 5

Het is inderdaad basisphp.
Maar heb vandaag echt teveel gedaan, ik block mezelf een beetje sadleyMoesten binnen 1 dag een volledig systeem maken en kijken hoever we kwamen, voor mn nieuwe opleiding. Ik ben al klaar ermee eigenlijk, maar dit zijn van die extra dingetjes die erbij kunnen.
Lezen is latig:

Quote:
(hoeft dus niet 100% correct te werken, het is een voorbeeld!)

Geeft dus weer aan dat je de code gewoon één op één hebt gekopieerd en geen moeite ervoor doet.
Aarclay schreef:
Tel je haakjes eens....
En die + moet een punt zijn, het is PHP en geen JS wink
Sorry, ik zit met school met C# en Java die wel met de "+" werkt in plaats van de "."

Ik doe er degelijk wel moeite voor.
Heb lopen kijken hoe ik het kan verhelpen, maar zonder enig geluk.
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Dan had je moeten zien dat de fout van regel 5 was dat er een ) te weinig stond om de if te sluiten.

Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8


if($_GET[act] == del)
{

if(file_exists(uploads/ + $_GET[file])
{

unlink(uploads/ + $_GET[file]);
}
}


Codeblok (voorbeeld.php):

1
2
3
4
5
6
7
8


if($_GET[act] == del)
{

if( file_exists(uploads/ . $_GET[file]) ) // <- Dit haakje dus
{
unlink(uploads/ . $_GET[file]);
}
}
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren