Solved

Using SaveVirtual and SaveAsVirtual to differnet directories

Posted on 2006-07-12
8
426 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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/…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

9 Experts available now in Live!

Get 1:1 Help Now