Link to home
Start Free TrialLog in
Avatar of poshlivin
poshlivin

asked on

Upload image in non web accessible folder

Hi experts,

We are developing a website where we enable users to upload images on our server. Right now I am storing the image in our database, without having an actual copy of it on our server. However, for creating the proofs, the customer needs the actual jpg/gif files.

The web hosting company only has ASP SimpleUpload installed, and they don't allow anonymous uploads to the server. They did mention that we could use a non web accessible folder, upload our images there, and later on move that image to the desired folder.

I just wanted to know a little more about what non web accessible folders are, how they provide the security over other folders, and how I can use them in my situation.

Would this code work to upload the file to the folder?
Dim File
  For Each File In MyUploader.Files.Items
    File.SaveToDisk Server.Mappath("../uploadimage") 'to store image in uploadimage folder
  Next

And then to move the file, I could use
<%
Dim fso

set fso = Server.CreateObject("Scripting.FileSystemObject")
fso.MoveFile "C:\source.txt", "C:\anotherfolder\source.txt"

Set fso = Nothing
%>

Do I really need to use ASP Simple Upload, aor do I need to ask for other components?

Thanks in advance

SOLUTION
Avatar of sybe
sybe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of poshlivin
poshlivin

ASKER

Thanks for the info. There is a little more i want to clarify - would my ASP pages be able to upload into the non web accessible folder?

If so, I guess Sybe's code would work right? And I should also be able to move from that folder onto my website folder, right?
If your hosts are simply not allowing any of your web accessible folders to have write access then yes you should be able to upload into the non accessible ones in the way sybes has suggested. But you will not be able to copy from there to your accessible ones with ASP because the server doesn't have write access!

You could still get to them and even display the images using the ADO Stream method I mentioned earlier to output them but it doesn't seem like a very suitable approach to be honest.

I'd suggest that you give it a test your self with the host just to check that the comment about non-accessible folders is indeed correct.

Steve
The web admin said he has restricted browser access to the folder UploadedFile, but only given write and execute permissions to it.

Would that be good enough to allow uploads?
Yes that should be ok although its a bit dodgy allowing write and execute permissions but thats his problem.

Steve
So now I used the code

 For Each File In MyUploader.Files.Items
    File.SaveToDisk ("UploadedFile") 'to store image in uploadimage folder
  Next

I have set a prompt to list all the file names and sizes uploaded.
Although I see those prompts, the file never gets writtten :(
My Mistake....
I used Server.MapPath instead of just the fiel name, and it's uploading the file alright!

Just one more question (and i am raising points on this)

How do I dynamically create a folder through ASP on my server?
Say user1 uploads an image - then I have to create a folder in his name and then move the files from the non web accessible folder to his folder. Is it possible?

Thanks
use the filesystemobject method of createfolder eg
fso.createfolder(foldername)

this will generate an error if the folder already exists so you need to check for its existence first with fso.folderexists(foldername)

HTH
Steve