Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using SaveVirtual and SaveAsVirtual to differnet directories

Posted on 2006-07-12
8
Medium Priority
?
436 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
[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
  • 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
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!

 

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 1000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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…
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 response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

609 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