Print Page | Close Window

Does a file exist?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=5415
Printed Date: 29 March 2026 at 3:12am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Does a file exist?
Posted By: zMaestro
Subject: Does a file exist?
Date Posted: 01 September 2003 at 4:29am

I am making a catalogue for products... a product image is present which is the product ID name.. ie product 55 picture is 55.jpg and so on...

Some products don't have picture, so can I check if the picture 55.jpg exists on the server so show it.. if not so display NoPic.jpg.

Thanks.




Replies:
Posted By: ljamal
Date Posted: 01 September 2003 at 7:18am
There is a FileExists Method for the FSO. I wouldn't recommend using it everytime you wanted to display a product picture, but I have used it when a product is added or updated.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Diep-Vriezer
Date Posted: 03 September 2003 at 2:42pm

Isn't dir() available in ASP classic? In .net it is. If so, just do:

If Dir(Server.Mappath("55.jpg") = "55.jpg" Then

    'The file exists

Else

    'The file doesn't exists

End If

If it doesn't, I've got no id..



-------------
Gone..


Posted By: MorningZ
Date Posted: 03 September 2003 at 8:30pm

if you dont feel like taking a hit on the server side.. you can do it in JS

<img src="55.jpg" onError="this.src='/images/1.gif'"/>

just make sure that "1.gif" exists somewhere.... i have mine set to a 1x1 blank gif



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Diep-Vriezer
Date Posted: 04 September 2003 at 8:26am
That's quite smart actually, better then mine

-------------
Gone..


Posted By: zMaestro
Date Posted: 07 September 2003 at 5:51am


Posted By: webpromo
Date Posted: 07 September 2003 at 7:37am

I am the developer of MyBootDisks.com and have several download partners...(mirror download sites).

I currently have the site setup so people can choose between several download servers...but what I want to do is make a script that will randomly select one from a listing and check to see if the file exists on that (REMOTE...most likely LINUX) server and if it does great...if not then randomize again and find a server that has that file.

Is there a way to do this using ASP?



Posted By: Diep-Vriezer
Date Posted: 07 September 2003 at 8:56am

Regular ASP or ASP.NET?

In ASP.NET it is possible (I guess), using the Dir() function. That works like this:

Please Note that this script does not work with regular ASP pages, and doesn't pick a random server

Dim ServerArray As Array, FileArray As Array

'File names on the servers (below)

FileArray.SetValue("file1.exe", 1)

FileArray.SetValue("file2.exe", 2)

FileArray.SetValue("file3.exe", 3)

'The mirror servers

ServerArray.SetValue("http://mirror1.com/" & FileArray.GetValue(1), 1)

ServerArray.SetValue("http://mirror2.com/" & FileArray.GetValue(2), 2)

ServerArray.SetValue("http://mirror3.com/" & FileArray.GetValue(3), 3)

'Check if the file exists

If Dir(ServerArray.GetValue(1)) = FileArray.GetValue(1) Then

'The file exists on server 1

Else

'The file doesn't exists, continue

If Dir(ServerArray.GetValue(2)) = FileArray.GetValue(2) Then

'The file exists on server 2

Else

'The file doesn't exists, continue

If Dir(ServerArray.GetValue(3)) = FileArray.GetValue(3) Then

'The file exists on server 3

Else

'The file doesn't exists, quit

Exit Sub

End If

End If

End If

'By Diep-Vriezer



-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 07 September 2003 at 8:56am
The tab's that I placed are gone... Enjoy reading..

-------------
Gone..


Posted By: webpromo
Date Posted: 07 September 2003 at 9:15am
I was looking for ASP version... :(


Posted By: Diep-Vriezer
Date Posted: 07 September 2003 at 1:07pm
If your server has the .NET framework, why don't you use this and name it Page.aspx? asp.net works fine with asp

-------------
Gone..


Posted By: webpromo
Date Posted: 07 September 2003 at 1:52pm
cause for the hoster i am with....they are charging more for .net supported servers...


Posted By: Diep-Vriezer
Date Posted: 07 September 2003 at 3:05pm
You can use one of mine if you want... (just one page, and low traffic plz)

-------------
Gone..


Posted By: webpromo
Date Posted: 07 September 2003 at 3:16pm

its ok...i would still prefer an ASP version....

traffic is not low sorry....about 6,000+ per day



Posted By: Diep-Vriezer
Date Posted: 07 September 2003 at 3:28pm
Wow, ok, I see the point. Well, I'll try and build something

-------------
Gone..


Posted By: 3BEPb
Date Posted: 08 September 2003 at 12:08am

If we'll return to catalog pics. What I usually doing - just creating a db column holding boolean value related to pic availability. I.e. it's default is False so when admin uploads the picture script write True in above mentioned field of product database.

I think it's a better way if we'll compare insignificant increase of DB size and displaying the value from selected product DB row vs. scanning entire folder searching the image.



Posted By: webpromo
Date Posted: 08 September 2003 at 6:10am
The only thing is that Access can only have 10 connection and with a site that has over 6000+ users per day that will be a prob.  I don't want to upgrade to SQL as yet.


Posted By: Diep-Vriezer
Date Posted: 08 September 2003 at 6:22am
Ow ow. Acces can only have 10 connections??? That explains quite a bit . Now I also got to make a SQL server (my site has quite alot view, and users)..

-------------
Gone..


Posted By: webpromo
Date Posted: 08 September 2003 at 6:33am
ya...but since it is only text in the database...if you dont have alot of text in each entry...then you can make faster connections and maybe able to even handle about 200 people on the site...though the connection will be started and ended so fast the user will not see a difference.


Posted By: Diep-Vriezer
Date Posted: 08 September 2003 at 6:34am
But, if I have like 1200 loggedin users, who view 3 tables in a acces database (security) with EACH page they visit... I think I've got a little problem now..

-------------
Gone..


Posted By: Diep-Vriezer
Date Posted: 08 September 2003 at 6:35am

How many connections can a SQL DB handle?



-------------
Gone..


Posted By: webpromo
Date Posted: 08 September 2003 at 6:45am
Ya, using Access may cause a problem.

SQL...I think is unlimited...but dont quote me on that.


Posted By: Diep-Vriezer
Date Posted: 08 September 2003 at 6:51am
 Well, looks like I've got something to do today..

-------------
Gone..


Posted By: webpromo
Date Posted: 08 September 2003 at 7:01am
making me an ASP script?


Posted By: Diep-Vriezer
Date Posted: 08 September 2003 at 7:05am
Lol, maybe actually. But back to the acces vb SQL thing, if I have, lets say 30 users who actively use the database (every time a page load, I need to peform checks, wich involve 5 tables).

Is this possible using acces? I mean, is Acces completly useless in this scenario? Acces XP was quite expensive (not that I bought it, but still, Microsoft must have thought about this).

-------------
Gone..


Posted By: 3BEPb
Date Posted: 08 September 2003 at 12:03pm

Originally posted by Diep-Vriezer Diep-Vriezer wrote:

But, if I have like 1200 loggedin users..

1200 users at once??? I'm sure that advertizement, you will sell on site with such traffic will cover your very own datacenter



Posted By: Diep-Vriezer
Date Posted: 08 September 2003 at 12:47pm
Well, it is true though. Really, I host websites (friends ed, but paid) and stuff and the it is really like that much (1200 is a bit much, but 900 would get very close)

-------------
Gone..



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net