a Button to delete ftp file

i have a php code that allows me to explore another server through php-ftp commands
i want to create a button that when i click on it … it deletes the selected file
this is the code i have :
[php]if (isset($_GET[‘file’]))
{
// Get file contents
$contents = file_get_contents(“ftp://$ftpUser:$ftpPass@$ftpHost/$startDir/” . urldecode($_GET[‘file’]));
// Get mime type
$finfo = new finfo(FILEINFO_MIME);
$mimeType = $finfo->buffer($contents);
// Set content type header and output file
header(“Content-type: $mimeType”);
echo $contents;
}
else {
$dir = (isset($_GET[‘dir’])) ? $_GET[‘dir’] : ‘’;
$conn = ftp_connect($ftpHost) or die(“Could not connect, please refresh in 2 seconds”);
ftp_login($conn, $ftpUser, $ftpPass);
// change dir to avoid ftp_rawlist bug for directory names with spaces in them
ftp_chdir($conn, “$startDir/$dir”);
// fetch the raw list
$list = ftp_rawlist($conn, ‘’);
reset($list);
while (list(, $item) = each($list)) {
if(!empty($item)) {
// Split raw result into pieces
$pieces = preg_split("/[\s]+/", $item, 9);
// Get item name
$name = $pieces[8];
// Skip parent and current dots
if ($name == ‘.’ || $name == ‘…’ || $name == ‘index.html’)
continue;
if($n%3 == 0){echo “

”;}
// Is directory
if ($pieces[0]{0} == ‘d’) {
echo “ {$name} ”;
}
$n++;
// Is file
if ($pieces[0]{0} !== ‘d’) {
echo “ {$name} ”;
}
}
}[/php]
and this is my homework (what i’ve tried) :
[php]if ($pieces[0]{0} !== ‘d’) {
echo “ {$name} ”;
}[/php]
according to php manual ftp_delete() is the method for removing a file through ftp
but it doesn’t work … some help please ?
this is a link for my test-page to understand more my question :
http://ahstpc.6te.net/site/1.php?dir=/subdirectory%202
Sponsor our Newsletter | Privacy Policy | Terms of Service