On Feb 13, 2008 6:03 PM, Richard Lynch <ceo@xxxxxxxxx> wrote: > > 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? > > I was actually doing what you just gave the code for. As of now, I was doing something like: """" for file in files: copy from source to folder echo "Copying files encapsulated in ob_flush()" tar the file which hardly takes time on the filessyetm but does take some time Provide the link to the tar """ So at the client side it was like: Copying file #1 Copying file #2 .... Download link I though I could apply some funkiness to it by using some AJAX based progress bar for which the example showed some sort of hooking and all which I thought was too much for such a job. I will talk to my boss regarding this and do the necessary. BTW, whats the issue with AJAX based approach? Any particular reason other then it seems to be a hack rather then an elegant solution (which is more then enough reason not to implement it...but I wonder if there is a technical reason to it too)? -- Ritesh http://www.riteshn.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php