473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Zip some folders and send by email

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
12 1728
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
<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

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
<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
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
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
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
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
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Karuppasamy | last post by:
Hi I want to populate all the files and folders of System in a Treeview control like Windows Explorer. I try this using File System Objects. But sometimes I am getting an error like 'Access...
3
by: musicloverlch | last post by:
Can MS Access be used to create folders on a drive? I need to create about 700 folders. Thanks, Laura
1
by: Nut Cracker | last post by:
Hello, If anyone can point me to a good ASP based Control Panel for IIS5, I would be much obliged. I hacked together an ASP site for file uploads and sharing. Its very simple, and basically...
5
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. ...
3
by: jerryyang_la1 | last post by:
I'm looking for a script / scripts that will allow me to control files that users can download. I would like to create 'General Folder' that any registered user can download from and private...
7
by: jonathandrott | last post by:
sorry newbie question probably. i'm trying to open an specific folder. open each file with in the folder individually and process each one. all the processing code has been written. i'm looking...
1
by: =?Utf-8?B?UmFjaW5yaG9uZGE=?= | last post by:
I had a hard drive failure and had to re-load Microsoft Office XP. When I first loaded, I had no data files so I imported my pst files from my old hard drive and now I have double of everything...
3
by: neopersia | last post by:
hello I'm designing a newsletter for my site and I gonna send my newsletters using mail() function. I want each user that receives newsletter be able to see just his email address in "TO" field and...
1
by: alqui | last post by:
Hi, I'm actually trying to resolve a simple problem. I'm trying to build my Web site. The structure of the Web site looks like that : /Element /Element/App_Code /Element/Admin...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.