Welcome Guest, Not a member yet? Register   Sign In
Delete files from directory
#11

[eluser]metaltapimenye[/eluser]
i assume you take clean url uh?.. so it the url looks like "http://www.host.dom/path/to/index/class/param/".
as far i know delete_files() takes url path to find the path.

means..
its deleting http://www.host.dom/path/to/index/class/...ic/videos/[adding some path in $old_video_path]. check it either those path really exist or not. else you have to delete it with
Code:
delete_files('../../public/videos/'.$old_video_path);

havent tested, just trying to help
#12

[eluser]ghprod[/eluser]
lol ...


this function delete_files return false :p

maybe i'lll try using relatvie path Smile

regards
#13

[eluser]Unknown[/eluser]
This is code of delete_files function :

function delete_files($path, $del_dir = FALSE, $level = 0)
{
// Trim the trailing slash
$path = preg_replace("|^(.+?)/*$|", "\\1", $path);

if ( ! $current_dir = @opendir($path))
return;

while(FALSE !== ($filename = @readdir($current_dir)))
{
if ($filename != "." and $filename != "..")
{
if (is_dir($path.'/'.$filename))
{
// Ignore empty folders
if (substr($filename, 0, 1) != '.')
{
delete_files($path.'/'.$filename, $del_dir, $level + 1);
}
}
else
{
unlink($path.'/'.$filename);
}
}
}
@closedir($current_dir);

if ($del_dir == TRUE AND $level > 0)
{
@rmdir($path);
}
}
You can see at http://ellislab.com/codeigniter/user-gui...elper.html show that :

delete_files('path')

Deletes ALL files contained in the supplied path. Example:
delete_files('./path/to/directory/');

It mean : you supply argument is path not file !

My English is not good :d
#14

[eluser]harman[/eluser]
i like this way:

@unlink('./mydir/resources/'.$MY_File);

'@' is magically suppress('ignore') Errors.
#15

[eluser]Unknown[/eluser]
For anyone still having trouble with this function, the path is relative to your base index.php file in your site. Not the html root, not the controller you call it from, but the base index.php file.

It's mentioned in the write_file() function above it in the documentation, but I only noticed that after hunting around for a little while.
#16

[eluser]hzr[/eluser]
Demanding people to help you isn't very polite and will only turn people away from helping you.
Also I suggest the next time you need help you use subject that describes your problem
#17

[eluser]skcin7[/eluser]
I am having trouble with delete_files(). My code looks like this:

delete_files($_SERVER['DOCUMENT_ROOT'] . '/database/' . $system->abbreviation, TRUE);

I would THINK that if anything, the path it should want would be the physical path of the files on the server. Apparently it wants a path that starts with http:// which could be why it doesn't work. So, you can't use $_SERVER['DOCUMENT_ROOT'] unfortunately. Also, I'm trying to use the CodeIgniter built in site_url() function and that doesn't seem to be helping me. This delete_files() function could use some improvement (I'd do it myself if I had the skill set).
#18

[eluser]skcin7[/eluser]
Ok, this is the solution I came up with. The following is an EXTENSION of the file helper. Save it as "MY_file_helper.php" and put it in application/helpers/ directory. From then on, you should be able to just call rrmdir($dir) to delete whatever directory you want. This is the solution I came up with. I just tested it and it works great.

Code:
<?php
function rrmdir($dir) {
  if (is_dir($dir)) {
   $objects = scandir($dir);
   foreach ($objects as $object) {
    if ($object != "." && $object != "..") {
    if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
    }
   }
   reset($objects);
   rmdir($dir);
  }
}
?>
#19

[eluser]rip_pit[/eluser]
[quote author="skcin7" date="1333766522"]Ok, this is the solution I came up with. [/quote]

Thanx! you are a god!!




Theme © iAndrew 2016 - Forum software by © MyBB