Solved

Using SaveVirtual and SaveAsVirtual to differnet directories

Posted on 2006-07-12
8
422 Views
Last Modified: 2012-06-21

I am trying to upload two images from the same form to two different directories.  My host requires that I use SaveVirtual and SaveAsVirtual.

I want the name of the file to be changes to the serial ID of the item that is being uploaded to the database (hence 'Name = "/"&pro_id&".jpg"')

It does work and upload the files to the correct directories with the correct filenames.

The problem:  It also uploads the origional image files in the /images/ folder.

How can I produce the same result without uploading the origional images?

Thanks

Here is the code I have:

<%      
      Set Upload = Server.CreateObject("Persits.Upload.1")
      Count = Upload.SaveVirtual("/images/")
      %>
<% = Count %> files uploaded.


      Set File1 = Upload.Files("filesmall")
      Set File2 = Upload.Files("filebig")
       Name = "/"&pro_id&".jpg"
      ' Save
            If Not File1 Is Nothing Then       File1.SaveAsVirtual "/images/products_small" & Name
            If Not File2 Is Nothing Then       File2.SaveAsVirtual "/images/products_big" & Name
      
0
Comment
Question by:dougbrill
  • 5
  • 3
8 Comments
 
LVL 25

Expert Comment

by:kevp75
Comment Utility
please post the entire code, not just a snippet of it.  your issue lies elsewhere
0
 

Author Comment

by:dougbrill
Comment Utility
Here is the entire code

Thanks

<%      
      
      Set Upload = Server.CreateObject("Persits.Upload.1")
      Count = Upload.SaveVirtual("/images/")
      %>
<% = Count %> files uploaded.

<!-- #include file="connectdb.asp"-->
<%
set rs=server.createobject("adodb.recordset")
rs.open "products" , conn,1,3
rs.addnew
      rs("pro_name")            = upload.form("txtName")
      rs("pro_detail")      = upload.form("txtDetail")
      rs("pro_color")            = upload.form("txtColor")
      rs("pro_item_no")      = upload.form("txtCode")
      rs("cat_id")                  = upload.form("category")
      if  upload.form("wholesale") = "Yes" then rs("wholesale") = true else rs("wholesale") = false      
      if  upload.form("normal") = "Yes" then rs("normal") = true else rs("normal") = false      
rs.update
pro_id = rs("pro_id")
set rs = server.CreateObject("adodb.recordset")
rs.open "product_size_price" , conn, 1,3
if  instr(upload.Form("txtSizePrice"),vbCrlf)  then arrLine = Split(trim(upload.Form("txtSizePrice")),vbCrlf) else arrLine  = array(trim(upload.Form("txtSizePrice")))
for each i in arrLine
      if i <> "" then
            arrSizePrice = Split(i,",")
            rs.addnew
            rs("pro_id")       = pro_id
            rs("pro_size")       = arrSizePrice(0)
            rs("pro_price") = arrSizePrice(1)
            rs("pro_weight") = arrSizePrice(2)
            rs.update
      end if
next
'#############################
set rs2 = server.CreateObject("adodb.recordset")
rs2.open "product_size_price_wholesale" , conn, 1,3
if  instr(upload.Form("txtSizePrice2"),vbCrlf)  then arrLine2 = Split(trim(upload.Form("txtSizePrice2")),vbCrlf) else arrLine2  = array(trim(upload.Form("txtSizePrice2")))
for each i2 in arrLine2
      if i2 <> "" then
            arrSizePrice2 = Split(i2,",")
            rs2.addnew
            rs2("pro_id")       = pro_id
            rs2("pro_size")       = arrSizePrice2(0)
            rs2("pro_price") = arrSizePrice2(1)
            rs2("pro_weight") = arrSizePrice2(2)
            rs2.update
      end if
next
'##################################
       Set File1 = Upload.Files("filesmall")
      Set File2 = Upload.Files("filebig")
       Name = "/"&pro_id&".jpg"
      ' Save
            If Not File1 Is Nothing Then       File1.SaveAsVirtual "/images/products_small" & Name
            If Not File2 Is Nothing Then       File2.SaveAsVirtual "/images/products_big" & Name
      


      
rs.close : conn.close : set rs=Nothing : set rs2=Nothing  : set conn=Nothing
%>
<script language="javascript">
            alert('saving data have done.');
            window.location='addproduct.asp';
</script>
0
 
LVL 25

Expert Comment

by:kevp75
Comment Utility
i'm curious.  You say it uploads the files to the correct directory, but also uploads them to the /images/ folder?

according to the code you posted they should only be getting uploaded to the /images/ folder, and nowhere else?

or is each product getting it's own folder?
my initial guess would be that the files are getting saved as /images/products_smalltheID.jpg and /images/products_bigtheID.jpg respectively.

try removing the / in:

Name = "/"&pro_id&".jpg"

and change:
If Not File1 Is Nothing Then      File1.SaveAsVirtual "/images/products_small" & Name
          If Not File2 Is Nothing Then      File2.SaveAsVirtual "/images/products_big" & Name


to:
If Not File1 Is Nothing Then      File1.SaveAsVirtual "/images/products_small/" & Name
          If Not File2 Is Nothing Then      File2.SaveAsVirtual "/images/products_big/" & Name
0
 

Author Comment

by:dougbrill
Comment Utility
The objective is to upload two images for each product.  1 is a thumbnail and the second is the large image.

The thumbnails should be going in the the "/images/products_small/" directory and the large image should be going into the "/images/products_big/" directory.
As I mentioned this is actually working.

In addition, it is uploading both images to the "/images/" folder with the files origional name.  That is what I do not want.

I tried what you suggested:

Set File1 = Upload.Files("filesmall")
      Set File2 = Upload.Files("filebig")
       Name = &pro_id&".jpg"
      ' Save
            If Not File1 Is Nothing Then       File1.SaveAsVirtual "/images/products_small/" & Name
            If Not File2 Is Nothing Then       File2.SaveAsVirtual "/images/products_big/" & Name


This is the result:

Microsoft VBScript compilation error '800a03ea'

Syntax error

/backend/insertproduct.asp, line 61

Name = &pro_id&".jpg"
-------^

Is it possible to upload to two differnet directories using SaveViirtual?
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 25

Expert Comment

by:kevp75
Comment Utility
sorry...little typo on our part.....
change:
Name = &pro_id&".jpg"

to:
Name = pro_id&".jpg"
0
 
LVL 25

Expert Comment

by:kevp75
Comment Utility
as far as I know it is.  (well....at least according to Persits manual)
0
 

Author Comment

by:dougbrill
Comment Utility
That again worked and saved the files with thier new name to the correct folders but it still saves the origional files to the /images/ folder.

Any other ideas?

Thanks
0
 
LVL 25

Accepted Solution

by:
kevp75 earned 250 total points
Comment Utility
can't believe I didn't see it before.

with these lines here:
Count = Upload.SaveVirtual("/images/")
<% = Count %>

you are saving the files to the /images/ directory

comment them out, and you will lose your file count, however the files will not get saved to the /images/ directory

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now