Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Does a file exist?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Does a file exist?

 Post Reply Post Reply Page  123 4>
Author
zMaestro View Drop Down
Senior Member
Senior Member


Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
Post Options Post Options   Thanks (0) Thanks(0)   Quote zMaestro Quote  Post ReplyReply Direct Link To This Post Topic: Does a file exist?
    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.

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post 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..
Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 04 September 2003 at 8:26am
That's quite smart actually, better then mine
Gone..
Back to Top
zMaestro View Drop Down
Senior Member
Senior Member


Joined: 11 May 2003
Location: Egypt
Status: Offline
Points: 1183
Post Options Post Options   Thanks (0) Thanks(0)   Quote zMaestro Quote  Post ReplyReply Direct Link To This Post Posted: 07 September 2003 at 5:51am
Back to Top
webpromo View Drop Down
Groupie
Groupie


Joined: 25 February 2002
Status: Offline
Points: 86
Post Options Post Options   Thanks (0) Thanks(0)   Quote webpromo Quote  Post ReplyReply Direct Link To This Post 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?

Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post 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..
Back to Top
 Post Reply Post Reply Page  123 4>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.