By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

what does this error mean?

100+
P: 142
Can someone please help me, I have coded a script that deletes the folder and folder items, it worked but now for some reason, I went to php.net and tried unlink, mkdir and FTP_delete but none works now, I get this error

Warning: ftp_delete() expects exactly 2 parameters, 1 given in /var/www/html/view/delete.php on line 6


My html form (you enter the folder name here)

[HTML]
<form id="dfolder" name="dfolder" method="post" action="delete.php">
<label> <strong>Please Enter the ID you of the image folder you wish to Delete</strong>.<br />
<br />
<input name="dfolder" type="text" id="dfolder" />
</label>
<p>
<label>
<input type="submit" name="Submit" value="Submit" />
</label>
</p>
</form>
[/HTML]




my php code:

[PHP]
<?php

$dfolder = $_POST['dfolder'];

$myFile = "$dfolder";
ftp_delete($myFile);

?>
[/PHP]
Aug 6 '07 #1
Share this Question
Share on Google+
6 Replies


dafodil
100+
P: 392
ftp_delete requires two parameters. You only passed one parameter.
You also need to pass the path of the file.
A sample in this site will give you an idea:
http://www.php.net/ftp_delete
Aug 6 '07 #2

100+
P: 142
Hi,

Does anyone know of a script where you just specify the folder and it delete all files and then the folder? I am searching the search engines but can't find nothing, I think it is cause my english aint my language and thus I type in the wrong stuff.
Aug 6 '07 #3

100+
P: 142
I found this script on the web, can someone please confrim for me if it is working or if it is me that is making not work

Original script
[PHP]

function rmdirtree($dirname) {
if (is_dir($dirname)) { //Operate on dirs only
$result=array();
if (substr($dirname,-1)!='/') {$dirname.='/';} //Append slash if necessary
$handle = opendir($dirname);
while (false !== ($file = readdir($handle))) {
if ($file!='.' && $file!= '..') { //Ignore . and ..
$path = $dirname.$file;
if (is_dir($path)) { //Recurse if subdir, Delete if file
$result=array_merge($result,rmdirtree($path));
}else{
unlink($path);
$result[].=$path;
}
}
}
closedir($handle);
rmdir($dirname); //Remove dir
$result[].=$dirname;
return $result; //Return array of deleted items
}else{
return false; //Return false if attempting to operate on a file
}
}
[/PHP]



My script

[PHP]
$dirname="c/"; ////////// I added this and just "c"


function rmdirtree($dirname) {
if (is_dir($dirname)) { //Operate on dirs only
$result=array();
if (substr($dirname,-1)!='c/') {$dirname.='c/';} //Append slash if necessary, I also added the dir c here
$handle = opendir($dirname);
while (false !== ($file = readdir($handle))) {
if ($file!='.' && $file!= '..') { //Ignore . and ..
$path = $dirname.$file;
if (is_dir($path)) { //Recurse if subdir, Delete if file
$result=array_merge($result,rmdirtree($path));
}else{
unlink($path);
$result[].=$path;
}
}
}
closedir($handle);
rmdir($dirname); //Remove dir
$result[].=$dirname;
return $result; //Return array of deleted items
}else{
return false; //Return false if attempting to operate on a file
}
}
[/PHP]
Aug 6 '07 #4

dafodil
100+
P: 392
Hi,

Does anyone know of a script where you just specify the folder and it delete all files and then the folder? I am searching the search engines but can't find nothing, I think it is cause my english aint my language and thus I type in the wrong stuff.
You could do it like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  $mydir = "/path/to/dir/"; 
  3. $d = dir($mydir); 
  4.  
  5. while($entry = $d->read()) 
  6.  
  7. {  
  8. if ($entry!= "." && $entry!= "..") 
  9. {  unlink($entry);  
  10. $d->close(); 
  11. rmdir($mydir); ?>
  12.  
Aug 6 '07 #5

100+
P: 142
Hi, got this neat script, this one works to delete dirs and their files.


[/PHP]
<?php

function remove_directory($dir) {
if ($handle = opendir("$dir")) {
while (false !== ($item = readdir($handle))) {
if ($item != "." && $item != "..") {
if (is_dir("$dir/$item")) {
remove_directory("$dir/$item");
} else {
unlink("$dir/$item");
echo " removing $dir/$item<br>\n";
}
}
}
closedir($handle);
rmdir($dir);
echo "removing $dir<br>\n";
}
}

remove_directory("/path/to/dir");

?>
[/PHP]
Aug 6 '07 #6

dafodil
100+
P: 392
That's also working, seems you find your way out. Post again if you got problems.
Aug 6 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.