By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

Zip some folders and send by email

P: n/a
Using the standard php functions found on most web servers - how do i
zip selected folders and have the zip file emailed to myself .

Not as a cron job or anything automated - it will be a option i will add
in the control panel .
Jul 6 '06 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Krustov wrote:
Using the standard php functions found on most web servers - how do i
zip selected folders and have the zip file emailed to myself .

Not as a cron job or anything automated - it will be a option i will add
in the control panel .
IMHO its a lot easier to do from the shell than in PHP. Write a shell script
and call it from PHP.

Something like:

#!/bin/bash

RECIP="$1"
if [ -z "$RECIP" ]; then
echo usage sendzip re*******@test.com file1 file2 file3 ....
fi

zip data.{$$}.zip $@
mail -a data{$$}.zip -s "Here are you warez" $RECIP <<<EOH

Here is the files you asked for.
EOH
C.

Jul 6 '06 #2

P: n/a
<comp.lang.php>
<Colin McKinnon>
<Thu, 06 Jul 2006 19:31:05 GMT>
<Zx****************@newsfe6-gui.ntli.net>
Using the standard php functions found on most web servers - how do i
zip selected folders and have the zip file emailed to myself .

Not as a cron job or anything automated - it will be a option i will add
in the control panel .

IMHO its a lot easier to do from the shell than in PHP. Write a shell script
and call it from PHP.
Haw pal - the only shells i know aboot is the wans fae the tally van .
--
Encrypted email address
www.emailuser.co.uk/?name=KRUSTOV
Jul 6 '06 #3

P: n/a

Krustov wrote:
Using the standard php functions found on most web servers - how do i
zip selected folders and have the zip file emailed to myself .

Not as a cron job or anything automated - it will be a option i will add
in the control panel .
Try this class I wrote some time ago:

http://www.conradish.net/bobo/show_s...ame=flyzip.php

It uses the zlib functions to compress the data. If the function aren't
there, then it just package the files.

Jul 6 '06 #4

P: n/a
<comp.lang.php>
<Chung Leong>
<6 Jul 2006 14:00:18 -0700>
<11*********************@p79g2000cwp.googlegroups. com>
Try this class I wrote some time ago:

http://www.conradish.net/bobo/show_s...ame=flyzip.php

It uses the zlib functions to compress the data. If the function aren't
there, then it just package the files.
Thanks for that , Although i dont understand most of it or what each
part does at this stage .

Will get back to you on that one after i do the usual google search on
the subject and learn some basics .
--
Encrypted email address
www.emailuser.co.uk/?name=KRUSTOV
Jul 6 '06 #5

P: n/a
In article <11*********************@p79g2000cwp.googlegroups. com>,
ch***********@hotmail.com says...
>
Krustov wrote:
Using the standard php functions found on most web servers - how do i
zip selected folders and have the zip file emailed to myself .

Not as a cron job or anything automated - it will be a option i will add
in the control panel .

Try this class I wrote some time ago:

http://www.conradish.net/bobo/show_s...ame=flyzip.php

It uses the zlib functions to compress the data. If the function aren't
there, then it just package the files.

Please forgive a silly question but can you tell me why you made it a
"class" rather than a simple set of functions?

nark
Jul 7 '06 #6

P: n/a
nark wrote:
In article <11*********************@p79g2000cwp.googlegroups. com>,
ch***********@hotmail.com says...

Krustov wrote:
Using the standard php functions found on most web servers - how do i
zip selected folders and have the zip file emailed to myself .
>
Not as a cron job or anything automated - it will be a option i will add
in the control panel .
Try this class I wrote some time ago:

http://www.conradish.net/bobo/show_s...ame=flyzip.php

It uses the zlib functions to compress the data. If the function aren't
there, then it just package the files.

Please forgive a silly question but can you tell me why you made it a
"class" rather than a simple set of functions?

nark
No reason really. The code actually started out as a just a set of
functions. I wrapped it in a class when I used it as an example for an
article in php|architect. You know how people tend to think anything
dress up as a "component" is more sophisticated.

Jul 7 '06 #7

P: n/a
nark <na****@home.home.comwrote:
>
ch***********@hotmail.com says...
>>
Krustov wrote:
Using the standard php functions found on most web servers - how do i
zip selected folders and have the zip file emailed to myself .

Not as a cron job or anything automated - it will be a option i will add
in the control panel .

Try this class I wrote some time ago:

http://www.conradish.net/bobo/show_s...ame=flyzip.php

It uses the zlib functions to compress the data. If the function aren't
there, then it just package the files.

Please forgive a silly question but can you tell me why you made it a
"class" rather than a simple set of functions?
It's fascinating that you would ask this question, and I suspect a PHP
newsgroup is the only one in which the value of encapsulation would be
questioned.

By defining a class, he is adding only one new name to the namespace,
instead of a whole set of names that might conflict with functions I
already have. In addition, it allows him to hide whatever state he might
need in the class object, instead of again polluting the namespace with
globals.

I know the PHP philosophy is to plop 100 functions into the global
namespace where one class name would do, but I suspect PHP programs would
be easier to read and maintain if the library were reorganized as classes
instead.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 8 '06 #8

P: n/a
Tim Roberts wrote:
It's fascinating that you would ask this question, and I suspect a PHP
newsgroup is the only one in which the value of encapsulation would be
questioned.

By defining a class, he is adding only one new name to the namespace,
instead of a whole set of names that might conflict with functions I
already have. In addition, it allows him to hide whatever state he might
need in the class object, instead of again polluting the namespace with
globals.
In economics there's an idea called "moral hazard," whereby a solution
to a social problem makes it worse because by moderating the negative
consequence it encourages the behaviors that causes the problem in the
first place. I have program in many languages and the only occasions
when I run into name collisions are in languages that have namespace,
notably C#.
I know the PHP philosophy is to plop 100 functions into the global
namespace where one class name would do, but I suspect PHP programs would
be easier to read and maintain if the library were reorganized as classes
instead.
Will that improve the productivity of a programmer, that's bottom line.
The answer is likely to be no. The cost of living with the potential of
name collision is low and incidental whereas the cost of reduced
visibility is high and is afflicted continually.

Jul 9 '06 #9

P: n/a
In article <ca********************************@4ax.com>, ti**@probo.com
says...
nark <na****@home.home.comwrote:
Please forgive a silly question but can you tell me why you made it a
"class" rather than a simple set of functions?

It's fascinating that you would ask this question, and I suspect a PHP
newsgroup is the only one in which the value of encapsulation would be
questioned.

By defining a class, he is adding only one new name to the namespace,
instead of a whole set of names that might conflict with functions I
already have. In addition, it allows him to hide whatever state he might
need in the class object, instead of again polluting the namespace with
globals.

I know the PHP philosophy is to plop 100 functions into the global
namespace where one class name would do, but I suspect PHP programs would
be easier to read and maintain if the library were reorganized as classes
instead.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Totally the reverse.

By wrapping it in a class he has made the code unnecessarily complex
and obtuse to read making understanding of the function difficult
and the code therefore harder to read and maintain.

The use of classes for small amounts of code such as used by PHP
programmers writing what are not much more than a simple series of
scripts is plain stupid and says more about the ego of the programmer
than anything else.

Anything that actually requires classes should bedone in a real reliable
language not a buggy script language like PHP.

Jul 9 '06 #10

P: n/a

wh*****@what.net wrote:
In article <ca********************************@4ax.com>, ti**@probo.com
says...
nark <na****@home.home.comwrote:
>Please forgive a silly question but can you tell me why you made it a
>"class" rather than a simple set of functions?
It's fascinating that you would ask this question, and I suspect a PHP
newsgroup is the only one in which the value of encapsulation would be
questioned.

By defining a class, he is adding only one new name to the namespace,
instead of a whole set of names that might conflict with functions I
already have. In addition, it allows him to hide whatever state he might
need in the class object, instead of again polluting the namespace with
globals.

I know the PHP philosophy is to plop 100 functions into the global
namespace where one class name would do, but I suspect PHP programs would
be easier to read and maintain if the library were reorganized as classes
instead.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.

Totally the reverse.

By wrapping it in a class he has made the code unnecessarily complex
and obtuse to read making understanding of the function difficult
and the code therefore harder to read and maintain.

The use of classes for small amounts of code such as used by PHP
programmers writing what are not much more than a simple series of
scripts is plain stupid and says more about the ego of the programmer
than anything else.

Anything that actually requires classes should bedone in a real reliable
language not a buggy script language like PHP.
try {
$zip = new ZipFile('foo.zip');
$zip->addFile($myFile);
$zip->addFile($file2);
$zip->write();
} catch { 'error making zipfile' }

vs:

$zip = zipfile_new('foo.zip');
if($zip == false) { die('couldn't creat file'); }
if(!zipfile_addfile($zip, $myfile)) { die('couldn't add file'); }
if(!zipfile_addfile($zip, $myfile2)) { die('couldn't add file 2'); }
if(!zipfile_write($zip)) {
die('couldn't write zipfile');
} else { 'do whatever' }

Which is more obtuse and harder to read is a matter of opinion, really.
Not to mention i didn't bother putting line breaks in because i hate
having to indent with spaces manually.

There are a whole bunch of other things that could be done, too, such
as, maybe he wants to use Rar compression or some other scheme in the
future. Simple: change new ZipFile to new RarFile, compared to
rewriting every zipfile_* function call. I could rail on about why
using the oop method would be more advantageous than the procedural
method, but it's such a dead subject.

Whichever you use is up to you, php doesn't require you to write in any
specific way.

Jul 9 '06 #11

P: n/a
Rik
wh*****@what.net wrote:
In article <ca********************************@4ax.com>,
ti**@probo.com says...
>nark <na****@home.home.comwrote:
>>Please forgive a silly question but can you tell me why you made it
a "class" rather than a simple set of functions?

It's fascinating that you would ask this question, and I suspect a
PHP newsgroup is the only one in which the value of encapsulation
would be questioned.

By defining a class, he is adding only one new name to the namespace,
instead of a whole set of names that might conflict with functions I
already have. In addition, it allows him to hide whatever state he
might need in the class object, instead of again polluting the
namespace with globals.

I know the PHP philosophy is to plop 100 functions into the global
namespace where one class name would do, but I suspect PHP programs
would be easier to read and maintain if the library were reorganized
as classes instead.
Totally the reverse.

By wrapping it in a class he has made the code unnecessarily complex
and obtuse to read making understanding of the function difficult
and the code therefore harder to read and maintain.
In this particular case, it might. But normally I like classes just for that
reason: avoid cluttering of variables, huge if..else.. statements or
switches. Also, scalability comes into play. It might be a simple script
now, but it might grow, which is easier done in OO in my opinion, because
everything has got it's own scope. That also means it almost certainly won't
interfere with already existing code in a project where you want to make us
of the class, which is often the case with procedural programming.

A good constructed class also makes it more clear to me personnaly what's
going on. I can follow code to different methods with ease, which can't
always be said for looking for the next }.
The use of classes for small amounts of code such as used by PHP
programmers writing what are not much more than a simple series of
scripts is plain stupid and says more about the ego of the programmer
than anything else.
I wouldn't know what the hell this has to do with ego. You don't pretend
anything by making it a class.
Anything that actually requires classes should bedone in a real
reliable language not a buggy script language like PHP.
Nothing _requires_ classes. Nothing _requires_ procedural programming. One
choice might serve the purpose (a lot) better then the other, but it's never
exclusive. The only time only one choice can be made is when it's required
by the desired language.

Grtz,
--
Rik Wasmus
Jul 9 '06 #12

P: n/a
Rik wrote:
In this particular case, it might. But normally I like classes just for that
reason: avoid cluttering of variables, huge if..else.. statements or
switches. Also, scalability comes into play. It might be a simple script
now, but it might grow, which is easier done in OO in my opinion, because
everything has got it's own scope. That also means it almost certainly won't
interfere with already existing code in a project where you want to make us
of the class, which is often the case with procedural programming.
There was a study a couple years ago comparing the productivity of
office workers with cluttered desks vs those with clean desks. As I
remembered it the conclusion was that those with cluterred desks tend
to be somewhat more productive, while those with the cleanest desks
tend to be least productive. It's not hard to understand why. Obviously
the person with the clean desk has to spend time cleaning it. Moreover,
he might tuck things away so thoroughly that he can't find them
anymore.

The same is true is programming. People don't look at code to
appreciate its beauty. In order to maintain a piece of code one has to
have a clear picture of what it does. Hidding details away that has
bearing on its behavior makes it harder to understand.

As for the code in question, like I said, it was written for an
article. So I prettied it up and gave it a snappy name. It does work
though.

Jul 9 '06 #13

This discussion thread is closed

Replies have been disabled for this discussion.