?
Solved

Zip a file with ASP

Posted on 2003-03-19
20
Medium Priority
?
559 Views
Last Modified: 2010-08-05
Hi, I've looked all over the place but many posts are over 2 years old and things may now be easier:

OUTLINE:
I want to create a wab based image gallery where after viewing images via thumbnail etc the user can download a full hi-resolution copy, but due to the size of the files (apx 10-20 MB each) i want to zip each one ON DEMAND from within ASP itself.

e.g. "click here to download this image" link will already have the image name etc attached to it, and will send it to a "zip me up" page.

QUESTION:
Is it possible in just ASP to create this? the "zip me up" asp page will need to simply take a filename (e.g. photo1.jpg) and compress it, then offer it to the user with the normal Zip download box.

I do have complete control over the 2 servers it will be needed on but would prefer not to install ActivX,etc if the whole thing can be done in pure ASP.

Saying that, all suggestions will be greatfully received as at present I have no real direction forward.

Neil Thompson
0
Comment
Question by:Neil Thompson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 7
  • 2
  • +1
20 Comments
 

Expert Comment

by:dattu070100
ID: 8165468
Hi Neil,

Instead of zipping the file every time the user requests for download, it is easy to zip all ur image files and create a link 2 zip file from the image, when clicked on image.  Brower automatically shows down load box when clicked.

ex:

<a href="/xxx/xxx/xyz.zip><img src="xyz.jpg"?</a>

Dattu
0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8165508
Apologies, my error. should have explained more:

As a council for someone to zip these all first we will be charged for the time each one takes, there are over 1000 and more will be added daily.

Secondly, the machine making the images will be a MAC which cannot run WinZip.

Therefore running it directly from the server seemed a good solution to the cost, time and MAC problems.

Neil
0
 
LVL 3

Expert Comment

by:newjack
ID: 8165589
What you will need is a Zip utility that allows you to create archives using a commandline tool.
That way you can run a Shell command from ASP using the WScript.Shell object to create the archive.

There are some free ziptools available that can do this for you, such as FreeZip or 7-Zip.

You'll have to give each archive a unique filename (maybe by including the ASP session number in the filename) to avoid overwriting the archives on mulitple requests.

This zipping will also be quite CPU intensive, but you might want to disable compression for the archives (since JPEGs are already compressed) so that should speed things up quite a bit.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Neil Thompson
ID: 8165625
I have now downloaded WZZIP (WinZip command line thingy) and it says the syntax needed is:

e.g.
wzzip image000002.zip image000002.tiff

I know nothing about WScript.Shell, can you advise how I would call that from an ASP page please?

Thank you.
0
 
LVL 3

Expert Comment

by:newjack
ID: 8165729
The WScript object is a part of the Microsoft Windows Scripting objects which are installed with MS VBScript.

Check out the online documentation at MSDN to learn all about what you can do with those objects:

WScript.Shell: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsobjwscript.asp

Windows Script Technologies in general:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/wsobjwscript.asp

0
 
LVL 3

Expert Comment

by:newjack
ID: 8165736
an example that runs notepad:

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)

0
 
LVL 1

Expert Comment

by:mjm42
ID: 8167439
Hi,

I think you can use the code below:

Set objWScript = Server.CreateObject("WScript.Shell")
strCMD = "[path to zipfile]\pkzip25.exe -add -silent [path to outputfile]\info.zip [file(s) to zip]"

objWScript.Run strCMD,,true

Now the zipped files are created and you can email them using the CDONTS object'
The outputfile has to be in a directory with an unique name.
The outputfile and directory can be deleted when the zip has been send.

Hope this solves your problem
0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8172427
Still cannot get it to work, even getting an error trying to open notepad?

any ideas.

heres the code I tried:
<%
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)
%>

heres the error:
Microsoft VBScript runtime error '800a01a8'
Object required: 'WScript'

I'm running Win 2k with full updates and SP's, IIS5 and IE6

Neil
0
 
LVL 3

Expert Comment

by:newjack
ID: 8172537
Oops,

my example was flawed,

instead of WScript.CreateObject it should be Server.CreateObject, because we are using ASP here, not WSH.

so try this instead:

<%
Set WshShell = Server.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)
%>
0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8172931
Just tried the above on the server and on my local machine  and still get this:

Microsoft VBScript runtime error '800a01a8'
Object required: 'WScript'
/website/zip.asp, line 3

<%
Set WshShell = Server.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)
%>
0
 
LVL 3

Expert Comment

by:newjack
ID: 8172956
It looks like the WScript components are not installed on your server.

Check if you can find the file wshom.ocx

It should be in your system32 folder.
0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8172999
yes, just checked and it is.

this code seems to at least be trying to open the file?

<%
  set wshell = server.createobject("wscript.shell")
  wshell.run "###2###notepad"
  set wshell = nothing
%>

I get this (the ###2###) is intentional as without it it does nothing?

error '80070002'
The system cannot find the file specified.
/zip.asp, line 7
0
 
LVL 3

Expert Comment

by:newjack
ID: 8173035
you can't use the WScript.ScriptFullName statement either,

the WScript. thing is used inside .vbs scripts, not ASP scripts, so that's why the error occurs,

also don't start commands that need user input,
notepad will probably cause your ASP page to hang as it will wait for notepad to be closed manually, but since it's running on your webserver that won't be possible,

try running you zip command instead, or "cmd.exe /C dir *.* > c:\test.txt" to redirect a dir command to a textfile.

0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8173057
yes, just checked and it is.

this code seems to at least be trying to open the file?

<%
  set wshell = server.createobject("wscript.shell")
  wshell.run "###2###notepad"
  set wshell = nothing
%>

I get this (the ###2###) is intentional as without it it does nothing?

error '80070002'
The system cannot find the file specified.
/zip.asp, line 7
0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8173059
yes, just checked and it is.

this code seems to at least be trying to open the file?

<%
  set wshell = server.createobject("wscript.shell")
  wshell.run "###2###notepad"
  set wshell = nothing
%>

I get this (the ###2###) is intentional as without it it does nothing?

error '80070002'
The system cannot find the file specified.
/zip.asp, line 7
0
 
LVL 1

Expert Comment

by:mjm42
ID: 8173068
maybe it's a problem in the IIS settings of your website.

In the properties of your site in IIS, under the tab Home Directory the application settings have to be set with script permissions.
Removing the application and setting it again sometimes works well.

Marcel
0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8173085
OK, were getting somewhere: this worked

<%
  set wshell = server.createobject("wscript.shell")
  wshell.run "cmd.exe /C dir *.* > c:\test.txt"
  set wshell = nothing
%>

so any idea how i would do the command line zip?

wzzip [options] zipfile [@listfile] [files...]
0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8173086
OK, were getting somewhere: this worked

<%
  set wshell = server.createobject("wscript.shell")
  wshell.run "cmd.exe /C dir *.* > c:\test.txt"
  set wshell = nothing
%>

so any idea how i would do the command line zip?

wzzip [options] zipfile [@listfile] [files...]
0
 
LVL 3

Accepted Solution

by:
newjack earned 500 total points
ID: 8173431
try getting your Zip command to work in an NT command window first,
than if you know how to zip files, use the same syntax for your command in your ASP page

0
 
LVL 3

Author Comment

by:Neil Thompson
ID: 8173506
Thanks newjack, final code worked as:

<%
  set wshell = server.createobject("wscript.shell")
  'wshell.run "cmd.exe  dir *.* > c:\test.txt"
  wshell.run "c:\wzzip -ex c:\kgc.zip c:\kgc.tif"
  set wshell = nothing
%>

Many thanks for your help

Neil
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question