How do you delete a zip file from a directory?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • comp.lang.php

    How do you delete a zip file from a directory?

    Once again, I thought my class method deleteZip() would do the trick,
    but it never deletes any .zip* file found in a directory:

    [PHP]
    /**
    * Delete any latent ZIP files found in this album. This method is to
    be inherited by all listing classes to allow for
    * list-wide deletion of latent server-created ZIP files for security
    purposes
    *
    * @access private
    * @see actual_path
    * @see is_class
    */
    function &deleteZip() { // STATIC VOID METHOD
    global $section, ${$section . 'LocationPath'} , $projectFullNam e;
    $album = $_REQUEST['album'];
    $locationPath = ($album) ? "${$section . 'LocationPath'}/$album" :
    ${$section . 'LocationPath'} ;
    if (@!is_class($th is->dbAP, 'DBActionPerfor mer')) $this->dbAP =& new
    DBActionPerform er(); // LOCAL INSTANTIATION UNLESS ALREADY EXISTING
    if (!$_ENV['windir']) { // UNIX VERSION
    $statMsg = exec("stat \"" . actual_path($lo cationPath) . "/*.zip*\"
    2>&1"); // USE UNIX CHECK 'stat' FOR LOCATING ANY ZIP FILES, DO
    DELETION IF AT LEAST 1 FOUND
    } else { // WINDOWS VERSION
    list($lsKommand , $lsRedirect) =
    @array_values($ this->dbAP->getKommandOSAr ray('ls'));
    $statMsg = exec("$lsKomman d \"" . actual_path($lo cationPath) .
    "/*.zip*\" $lsRedirect");
    }
    if (@!unlink(actua l_path($locatio nPath) . '/*.zip*') &&
    !preg_match('/no such file/i', $statMsg)) { // WEB SERVER CANNOT
    DELETE ZIP FILES
    list($removeKom mand, $removeRedirect ) =
    @array_values($ this->dbAP->getKommandOSAr ray('rmdir-force'));
    $msg = exec("$removeKo mmand \"" . actual_path($lo cationPath) .
    "/*.zip*\" $removeRedirect "); // ALLOW FOR THE SERVER ITSELF TO
    DELETE THEM
    if (preg_match('/^rm:/i', $msg) || ($_ENV['windir'] && $msg))
    die("$projectFu llName shut down due to security issue with
    potentially damaging ZIP file in \"$locationPath \", please contact
    administrator<p >Error: $msg");
    }
    }

    [/PHP]

    This is what happens:

    statMsg = stat: cannot stat `/www/html/tools/app/images/doom/*.zip*':
    No such file or directory
    um, sorry but there *IS* at lease 1 zip file in
    /www/html/tools/app/images/doom called images_of_doom. zip that is
    auto-generated and does exist when I do "ls -l" via command line,
    permissions of 0644.

    How do I delete it and any other ZIP file, plain and simple, I thought
    this would work and it doesn't, please help

    thanx
    phil

  • petersprc@gmail.com

    #2
    Re: How do you delete a zip file from a directory?

    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.");
    }

    comp.lang.php wrote:
    Once again, I thought my class method deleteZip() would do the trick,
    but it never deletes any .zip* file found in a directory:
    >
    [PHP]
    /**
    * Delete any latent ZIP files found in this album. This method is to
    be inherited by all listing classes to allow for
    * list-wide deletion of latent server-created ZIP files for security
    purposes
    *
    * @access private
    * @see actual_path
    * @see is_class
    */
    function &deleteZip() { // STATIC VOID METHOD
    global $section, ${$section . 'LocationPath'} , $projectFullNam e;
    $album = $_REQUEST['album'];
    $locationPath = ($album) ? "${$section . 'LocationPath'}/$album" :
    ${$section . 'LocationPath'} ;
    if (@!is_class($th is->dbAP, 'DBActionPerfor mer')) $this->dbAP =& new
    DBActionPerform er(); // LOCAL INSTANTIATION UNLESS ALREADY EXISTING
    if (!$_ENV['windir']) { // UNIX VERSION
    $statMsg = exec("stat \"" . actual_path($lo cationPath) . "/*.zip*\"
    2>&1"); // USE UNIX CHECK 'stat' FOR LOCATING ANY ZIP FILES, DO
    DELETION IF AT LEAST 1 FOUND
    } else { // WINDOWS VERSION
    list($lsKommand , $lsRedirect) =
    @array_values($ this->dbAP->getKommandOSAr ray('ls'));
    $statMsg = exec("$lsKomman d \"" . actual_path($lo cationPath) .
    "/*.zip*\" $lsRedirect");
    }
    if (@!unlink(actua l_path($locatio nPath) . '/*.zip*') &&
    !preg_match('/no such file/i', $statMsg)) { // WEB SERVER CANNOT
    DELETE ZIP FILES
    list($removeKom mand, $removeRedirect ) =
    @array_values($ this->dbAP->getKommandOSAr ray('rmdir-force'));
    $msg = exec("$removeKo mmand \"" . actual_path($lo cationPath) .
    "/*.zip*\" $removeRedirect "); // ALLOW FOR THE SERVER ITSELF TO
    DELETE THEM
    if (preg_match('/^rm:/i', $msg) || ($_ENV['windir'] && $msg))
    die("$projectFu llName shut down due to security issue with
    potentially damaging ZIP file in \"$locationPath \", please contact
    administrator<p >Error: $msg");
    }
    }
    >
    [/PHP]
    >
    This is what happens:
    >
    statMsg = stat: cannot stat `/www/html/tools/app/images/doom/*.zip*':
    No such file or directory
    >
    um, sorry but there *IS* at lease 1 zip file in
    /www/html/tools/app/images/doom called images_of_doom. zip that is
    auto-generated and does exist when I do "ls -l" via command line,
    permissions of 0644.
    >
    How do I delete it and any other ZIP file, plain and simple, I thought
    this would work and it doesn't, please help
    >
    thanx
    phil

    Comment

    • comp.lang.php

      #3
      Re: How do you delete a zip file from a directory?


      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

      >
      comp.lang.php wrote:
      Once again, I thought my class method deleteZip() would do the trick,
      but it never deletes any .zip* file found in a directory:

      [PHP]
      /**
      * Delete any latent ZIP files found in this album. This method is to
      be inherited by all listing classes to allow for
      * list-wide deletion of latent server-created ZIP files for security
      purposes
      *
      * @access private
      * @see actual_path
      * @see is_class
      */
      function &deleteZip() { // STATIC VOID METHOD
      global $section, ${$section . 'LocationPath'} , $projectFullNam e;
      $album = $_REQUEST['album'];
      $locationPath = ($album) ? "${$section . 'LocationPath'}/$album" :
      ${$section . 'LocationPath'} ;
      if (@!is_class($th is->dbAP, 'DBActionPerfor mer')) $this->dbAP =& new
      DBActionPerform er(); // LOCAL INSTANTIATION UNLESS ALREADY EXISTING
      if (!$_ENV['windir']) { // UNIX VERSION
      $statMsg = exec("stat \"" . actual_path($lo cationPath) . "/*.zip*\"
      2>&1"); // USE UNIX CHECK 'stat' FOR LOCATING ANY ZIP FILES, DO
      DELETION IF AT LEAST 1 FOUND
      } else { // WINDOWS VERSION
      list($lsKommand , $lsRedirect) =
      @array_values($ this->dbAP->getKommandOSAr ray('ls'));
      $statMsg = exec("$lsKomman d \"" . actual_path($lo cationPath) .
      "/*.zip*\" $lsRedirect");
      }
      if (@!unlink(actua l_path($locatio nPath) . '/*.zip*') &&
      !preg_match('/no such file/i', $statMsg)) { // WEB SERVER CANNOT
      DELETE ZIP FILES
      list($removeKom mand, $removeRedirect ) =
      @array_values($ this->dbAP->getKommandOSAr ray('rmdir-force'));
      $msg = exec("$removeKo mmand \"" . actual_path($lo cationPath) .
      "/*.zip*\" $removeRedirect "); // ALLOW FOR THE SERVER ITSELF TO
      DELETE THEM
      if (preg_match('/^rm:/i', $msg) || ($_ENV['windir'] && $msg))
      die("$projectFu llName shut down due to security issue with
      potentially damaging ZIP file in \"$locationPath \", please contact
      administrator<p >Error: $msg");
      }
      }

      [/PHP]

      This is what happens:

      statMsg = stat: cannot stat `/www/html/tools/app/images/doom/*.zip*':
      No such file or directory
      um, sorry but there *IS* at lease 1 zip file in
      /www/html/tools/app/images/doom called images_of_doom. zip that is
      auto-generated and does exist when I do "ls -l" via command line,
      permissions of 0644.

      How do I delete it and any other ZIP file, plain and simple, I thought
      this would work and it doesn't, please help

      thanx
      phil

      Comment

      • Tim Roberts

        #4
        Re: How do you delete a zip file from a directory?

        "comp.lang. php" <phillip.s.powe ll@gmail.comwro te:
        >
        >petersprc@gmai l.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.

        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.

        Comment

        • comp.lang.php

          #5
          Re: How do you delete a zip file from a directory?


          Tim Roberts wrote:
          "comp.lang. php" <phillip.s.powe ll@gmail.comwro te:
          >

          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.
          Ok cool, however, the requirements for this portable web app is that it
          must work in both Unix and Windows environments equally, thus,
          obviously can't just do "ls *.zip" but also "dir /w *.zip" as well; how
          does "glob" play with Windows?
          >
          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.
          -
          clever subdirectories are an option inasmuch as PHP requires literal
          paths for some of its functionality (I wrote a function "actual_pat h()"
          that takes care of that anyway), however, as this is a portable web
          application, I am not sure if that is a viable one, as this application
          is designed to "pack up and go" and install anywhere on the planet (or
          it should), one simply could not do mod_rewrite on the fly, only an
          admin customizing my tool could do that on their end. Good to suggest
          though

          Phil

          PS: I figured something out that might work for Unix/Windows:

          [PHP]
          if (!$_ENV['windir'] && !$_SERVER['windir']) {
          $msg = exec('stat ' . actual_path($lo cationPath) . '/*.zip* 2>&1');
          } else {
          list($lsKommand , $lsRedirect) =
          @array_values($ this->getKommandOSAr ray('ls-l')); // GETS "ls" COMMAND
          APPROPRIATE FOR NON-UNIX SYSTEMS
          $msg = exec("$lsKomman d \"" . actual_path($lo cationPath) . "/*.zip*\"
          $lsRedirect");
          }
          [/PHP]
          -
          - Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          • Jerry Stuckle

            #6
            Re: How do you delete a zip file from a directory?

            comp.lang.php wrote:
            Tim Roberts wrote:
            >
            >
            >
            Ok cool, however, the requirements for this portable web app is that it
            must work in both Unix and Windows environments equally, thus,
            obviously can't just do "ls *.zip" but also "dir /w *.zip" as well; how
            does "glob" play with Windows?
            >
            Why not use the directory functions, such as opendir(), readdir(), etc.?
            They work on all systems. You'll have to test the file extensions,
            but it shouldn't be too bad as the information is cached.

            >
            >
            clever subdirectories are an option inasmuch as PHP requires literal
            paths for some of its functionality (I wrote a function "actual_pat h()"
            that takes care of that anyway), however, as this is a portable web
            application, I am not sure if that is a viable one, as this application
            is designed to "pack up and go" and install anywhere on the planet (or
            it should), one simply could not do mod_rewrite on the fly, only an
            admin customizing my tool could do that on their end. Good to suggest
            though
            >
            Phil
            >
            PS: I figured something out that might work for Unix/Windows:
            >
            [PHP]
            if (!$_ENV['windir'] && !$_SERVER['windir']) {
            $msg = exec('stat ' . actual_path($lo cationPath) . '/*.zip* 2>&1');
            } else {
            list($lsKommand , $lsRedirect) =
            @array_values($ this->getKommandOSAr ray('ls-l')); // GETS "ls" COMMAND
            APPROPRIATE FOR NON-UNIX SYSTEMS
            $msg = exec("$lsKomman d \"" . actual_path($lo cationPath) . "/*.zip*\"
            $lsRedirect");
            }
            [/PHP]
            -
            >
            >>- Tim Roberts, timr@probo.com
            > Providenza & Boekelheide, Inc.
            >
            >
            $_SERVER['DOCUMENT_ROOT'] always points to the root directory of the
            server, no matter where it is or what platform you're running Apache on
            (it also works with IIS). From there is' a simple matter to append the
            relative path from the document root to the directory you want.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • comp.lang.php

              #7
              Re: How do you delete a zip file from a directory?


              Jerry Stuckle wrote:
              comp.lang.php wrote:
              Tim Roberts wrote:



              Ok cool, however, the requirements for this portable web app is that it
              must work in both Unix and Windows environments equally, thus,
              obviously can't just do "ls *.zip" but also "dir /w *.zip" as well; how
              does "glob" play with Windows?
              >
              Why not use the directory functions, such as opendir(), readdir(), etc.?
              They work on all systems. You'll have to test the file extensions,
              but it shouldn't be too bad as the information is cached.
              >
              >


              clever subdirectories are an option inasmuch as PHP requires literal
              paths for some of its functionality (I wrote a function "actual_pat h()"
              that takes care of that anyway), however, as this is a portable web
              application, I am not sure if that is a viable one, as this application
              is designed to "pack up and go" and install anywhere on the planet (or
              it should), one simply could not do mod_rewrite on the fly, only an
              admin customizing my tool could do that on their end. Good to suggest
              though

              Phil

              PS: I figured something out that might work for Unix/Windows:

              [PHP]
              if (!$_ENV['windir'] && !$_SERVER['windir']) {
              $msg = exec('stat ' . actual_path($lo cationPath) . '/*.zip* 2>&1');
              } else {
              list($lsKommand , $lsRedirect) =
              @array_values($ this->getKommandOSAr ray('ls-l')); // GETS "ls" COMMAND
              APPROPRIATE FOR NON-UNIX SYSTEMS
              $msg = exec("$lsKomman d \"" . actual_path($lo cationPath) . "/*.zip*\"
              $lsRedirect");
              }
              [/PHP]
              -
              >- Tim Roberts, timr@probo.com
              Providenza & Boekelheide, Inc.
              $_SERVER['DOCUMENT_ROOT'] always points to the root directory of the
              server, no matter where it is or what platform you're running Apache on
              (it also works with IIS).
              [snip]

              That doesn't address the fact that your directory, stemming from
              $_SERVER['DOCUMENT_ROOT'], could be "/var/www/html/blah/foo" or
              "C:\Program Files\Apache Group\Apache\ht docs\blah\foo". Which is why I
              will want to delete all of one type of file from a directory, the issue
              lies in the fact that I am wanting to use command-line calls to remove
              them all at one time (which honestly I thought was a time saver, but
              honestly, is that slower or faster than your suggestion of opendir() -
              readdir() while loop? I would think the while loop is slower as it has
              to loop where a command-line remove command would be faster, but that's
              just me), by using the * wildcard I cannot encase the path structure in
              double-quotes, but in Windows, my directory from the doc root might
              have spaces in it:

              c:\Program Files\Apache Group\Apache\ht docs\My Directory\blah\ foo

              Why anyone would do that would be beyond me, but it is viable to occur
              of course.

              Also, for some strange reason, whenever I do this, it fails in spite of
              the fact that $_SERVER['DOCUMENT_ROOT'] contains the path from the root
              to the docroot:

              [PHP]
              list($removeKom mand, $removeRedirect ) =
              @array_values($ dbAP->getKommandOSAr ray('rmdir')); // GETS EITHER
              WINDOWS OR NON-WINDOWS REMOVE COMMANDS AND REDIRECTION
              $msg = exec("$removeKo mmand \"" . actual_path($_S ERVER['DOCUMENT_ROOT']
              .. '/blah/foo') . "/*.zip*\" $removeRedirect ");
              [/PHP]

              Phil

              Comment

              • Jerry Stuckle

                #8
                Re: How do you delete a zip file from a directory?

                comp.lang.php wrote:
                Jerry Stuckle wrote:
                >
                <snip>
                >>$_SERVER['DOCUMENT_ROOT'] always points to the root directory of the
                >>server, no matter where it is or what platform you're running Apache on
                >>(it also works with IIS).
                >
                >
                [snip]
                >
                That doesn't address the fact that your directory, stemming from
                $_SERVER['DOCUMENT_ROOT'], could be "/var/www/html/blah/foo" or
                "C:\Program Files\Apache Group\Apache\ht docs\blah\foo". Which is why I
                will want to delete all of one type of file from a directory, the issue
                lies in the fact that I am wanting to use command-line calls to remove
                them all at one time (which honestly I thought was a time saver, but
                honestly, is that slower or faster than your suggestion of opendir() -
                readdir() while loop? I would think the while loop is slower as it has
                to loop where a command-line remove command would be faster, but that's
                just me), by using the * wildcard I cannot encase the path structure in
                double-quotes, but in Windows, my directory from the doc root might
                have spaces in it:
                >
                c:\Program Files\Apache Group\Apache\ht docs\My Directory\blah\ foo
                >
                Why anyone would do that would be beyond me, but it is viable to occur
                of course.
                >

                Either way, $_SERVER['DOCUMENT_ROOT'] will point at your web root
                directory. Just add your relative path from the root directory - which
                the program should know already, anyway. It's just much easier to
                reference the web server root directory all the time than to try to
                compute the relative path. So you would just use:

                $_SERVER['DOCUMENT_ROOT'] . '/blah/foo'

                for your directory (yes, Windows understands forward slashes, also -
                just the command processor doesn't).

                And spaces are not a problem.

                Using the PHP directory functions is going to be slower - but it is
                transparent to the system. And many shared hosts do not allow PHP
                programs to execute shell commands. This will always work, as long as
                the files have the appropriate permissions (and if they don't, the shell
                command will fail, also).
                Also, for some strange reason, whenever I do this, it fails in spite of
                the fact that $_SERVER['DOCUMENT_ROOT'] contains the path from the root
                to the docroot:
                >
                [PHP]
                list($removeKom mand, $removeRedirect ) =
                @array_values($ dbAP->getKommandOSAr ray('rmdir')); // GETS EITHER
                WINDOWS OR NON-WINDOWS REMOVE COMMANDS AND REDIRECTION
                $msg = exec("$removeKo mmand \"" . actual_path($_S ERVER['DOCUMENT_ROOT']
                . '/blah/foo') . "/*.zip*\" $removeRedirect ");
                [/PHP]
                >
                Phil
                >
                You don't need actual_path, for one thing. You already have it. And
                not knowing what actually is passed in $removeKommand or
                $removeRedirect , it's hard to say what happened.

                Why not put your command into a string then echo it to see what's
                actually in it? And the message that's returned.


                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstucklex@attgl obal.net
                =============== ===

                Comment

                • Tim Roberts

                  #9
                  Re: How do you delete a zip file from a directory?

                  "comp.lang. php" <phillip.s.powe ll@gmail.comwro te:
                  >
                  >Tim Roberts wrote:
                  >>
                  >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.
                  >
                  >Ok cool, however, the requirements for this portable web app is that it
                  >must work in both Unix and Windows environments equally, thus,
                  >obviously can't just do "ls *.zip" but also "dir /w *.zip" as well;
                  I did not suggest that you actually use "ls *.zip" in your app. I
                  suggested that you do it ONE TIME and notice how quickly it runs, because
                  it uses essentially the same mechanism that "glob" will use. My purpose in
                  doing so was merely to reassure you that "glob" is not inefficient.
                  >how does "glob" play with Windows?
                  It works fine on Windows.
                  --
                  - Tim Roberts, timr@probo.com
                  Providenza & Boekelheide, Inc.

                  Comment

                  • comp.lang.php

                    #10
                    Re: How do you delete a zip file from a directory?


                    Tim Roberts wrote:
                    "comp.lang. php" <phillip.s.powe ll@gmail.comwro te:
                    >

                    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_exis ts('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($oldP ath, $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($oldPa th);
                    while (($fyl = @readdir($dirID )) !== false) if
                    (@!rename(actua l_path("$oldPat h/$fyl"), actual_path($ne wPath))) return
                    false;
                    @closedir($dirI D);
                    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.

                    Comment

                    • Marcin Dobrucki

                      #11
                      Re: How do you delete a zip file from a directory?

                      comp.lang.php wrote:
                      >
                      if (@!is_class($th is->dbAP, 'DBActionPerfor mer')) $this->dbAP =& new
                      DBActionPerform er(); // LOCAL INSTANTIATION UNLESS ALREADY EXISTING
                      I don't know about the actual unlinking of zip files, etc, but AFAIK
                      you can't create objects by reference. This should be:

                      ....$this->dbAP = new DBActionPerform er();

                      Comment

                      • comp.lang.php

                        #12
                        Re: How do you delete a zip file from a directory?


                        Marcin Dobrucki wrote:
                        comp.lang.php wrote:

                        if (@!is_class($th is->dbAP, 'DBActionPerfor mer')) $this->dbAP =& new
                        DBActionPerform er(); // LOCAL INSTANTIATION UNLESS ALREADY EXISTING
                        >
                        I don't know about the actual unlinking of zip files, etc, but AFAIK
                        you can't create objects by reference. This should be:
                        >
                        ...$this->dbAP = new DBActionPerform er();
                        Um I'm sorry but yes you can. I've been doing this in PHP for years
                        with no problem:

                        $this->dbAP =& new DBActionPerform er();

                        Phil

                        Comment

                        Working...