Solved

Using SaveVirtual and SaveAsVirtual to differnet directories

Posted on 2006-07-12
8
429 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
ID: 17094269
please post the entire code, not just a snippet of it.  your issue lies elsewhere
0
 

Author Comment

by:dougbrill
ID: 17094354
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
ID: 17094483
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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:dougbrill
ID: 17094590
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
 
LVL 25

Expert Comment

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

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

Expert Comment

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

Author Comment

by:dougbrill
ID: 17095557
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
ID: 17095811
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
ASP CDO - Limiting Connections 3 59
If condition on Html with Asp 11 29
key press alert 2 32
return false must be hit after calling certain command 10 33
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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