#  a Button to delete ftp file

**URL:** <https://www.phphelp.com/t/a-button-to-delete-ftp-file/18930>\
**Category:** General PHP Help\
**Created:** [November 17, 2012, 6:44pm UTC](https://www.phphelp.com/t/a-button-to-delete-ftp-file/18930 "2012-11-17T18:44:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amine](https://www.phphelp.com/user_avatar/www.phphelp.com/amine/32/818_2.png) [@Amine](https://www.phphelp.com/u/Amine)\
**Post date:** [November 17, 2012, 6:44pm UTC](https://www.phphelp.com/t/a-button-to-delete-ftp-file/18930/1 "2012-11-17T18:44:28Z")

</div>

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](http://ahstpc.6te.net/site/1.php?dir=/subdirectory%202)
