Re: Copying 1000s files and showing the progress

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, February 13, 2008 4:28 am, Ritesh Nadhani wrote:
> I have a situation where I have to copy something like 1000 files one
> by one to a temporary folder. Tar it using the system tar command and
> let the user download the tar file.
>
> Now while the copy is going on at server, I want to show some progress
> to the user at client side. Most of the tutorial I found on net was
> about showing progress while a file is being uploaded from client to
> server. In this case the client has the info but for my case, the
> client has no info.
>
> A similar was problem was solved at
> http://menno.b10m.net/blog/blosxom/perl/cgi-upload-hook.html but its
> in PERL and uses some form of hook. I have no clue how to do it in
> PHP.
>
> Any clues or right direction would be awesome.

First of all, don't do that. :-)

Instead, set up a "job" system of what should be copied/tarred, and
then notify the user via email.

Don't make the user sit there waiting for the computer!

If you absolutely HAVE to do this due to a pointy-haired boss...

<?php
  $path = "/full/path/to/1000s/of/files";
  $dir = opendir($path) or die("Change that path");
  $tmp = tmpname(); //or whatever...
  while (($file = readdir($dir)) !== false){
    echo "$file<br />\n";
    copy("$path/$file", "/tmp/$tmp/$path");
  }
  exec("tar -cf /tmp/$tmp.tar /tmp/$tmp/", $output, $error);
  echo implode("<br />\n", $output);
  if ($error){
    //handle error here!
    die("OS Error: $error");
  }
?>

shameless plug:
//handle error here could perhaps use this:
http://l-i-e.com/perror.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux