You are here: Re: How do you delete a zip file from a directory? « PHP Programming Language « IT news, forums, messages
Re: How do you delete a zip file from a directory?

Posted by comp.lang.php on 10/19/06 17:22

Tim Roberts wrote:
> "comp.lang.php" <phillip.s.powell@gmail.com> wrote:
>
> >
> >petersprc@gmail.com wrote:
> >> To expand a wildcard pattern, try the glob function. unlink isn't able
> >> to handle wildcards. For instance:
> >>
> >> $zips = glob("$theDir/*.zip");
> >> if ($zips === false) {
> >> die("glob failed.");
> >> }
> >> foreach ($zips as $zip) {
> >> unlink($zip) or die("unlink failed.");
> >> }
> >
> >Thanx but how efficient is that? You could be looping through a
> >directory potentially containing thousands of images within my
> >application each time you display a list of them
>
> You shouldn't worry too much about efficiency until you try it. Try doing
> an "ls *.zip" from a command line; the "glob" is going to take roughly the
> same time. The Unix directory APIs are pretty efficient.

I wrote a function that will be used in case you don't have shell
access as a backup, that way, you will always have a way of performing
the same functionality whether you have shell access or not.

as far as "glob" goes, I checked here
http://us3.php.net/manual/en/function.glob.php under the first note,
and this portable application could be used to access and handle remote
files, thus "glob" will fail there (thus that's why I'm not using
"glob"):

[PHP]
if (!function_exists('move_all')) {
/**
* This function will perform the moving of all files from one
directory to another. Will return boolean as other PHP file/directory
commands will do as well
*
* "move_all()" will take the place of command-line "mv
/path/to/my/files/* /new/path/for/my/files" if the system environment
does not permit usage of command-line shell access. It will
* loop through the directory and use {@link
http://us3.php.net/manual/en/function.rename.php rename()} to move each
file individually
*
* @access public
* @param mixed $origPath
* @param mixed $newPath
* @return boolean
* @see actual_path
*/
function &move_all($oldPath, $newPath) {
if (!is_dir(actual_path($oldPath))) trigger_error("\"$oldPath\" is not
a valid source directory", E_USER_WARNING);
if (!is_dir(actual_path($newPath))) trigger_error("\"$newPath\" is not
a valid destination directory", E_USER_WARNING);
$dirID = @opendir($oldPath);
while (($fyl = @readdir($dirID)) !== false) if
(@!rename(actual_path("$oldPath/$fyl"), actual_path($newPath))) return
false;
@closedir($dirID);
return true;
}
}

[/PHP]

So thanx a lot for the suggestions as it totally helps keep this
portable web app being, well, more portable!

>
> On the other hand, once you get into "thousands" of images, you might
> consider some clever subdirectories. I have a client that stores PDF and
> JPG files, where the names have the form 'p12345.pdf'. I use mod_rewrite
> to change that to a directory tree p1/23/p12345.pdf. That way, there are
> no more than 100 files per directory.
> --
> - Tim Roberts, timr@probo.com
> Providenza & Boekelheide, Inc.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация