Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 560
  • Last Modified:

Zip a file with ASP

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
Neil Thompson
Asked:
Neil Thompson
  • 10
  • 7
  • 2
  • +1
1 Solution
 
dattu070100Commented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
newjackCommented:
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
Technology Partners: 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!

 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
newjackCommented:
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
 
newjackCommented:
an example that runs notepad:

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

0
 
mjm42Commented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
newjackCommented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
newjackCommented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
newjackCommented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
mjm42Commented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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
 
newjackCommented:
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
 
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 10
  • 7
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now