• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1338
  • Last Modified:

Use Jquery or AJAX to check if a file exists

How could I use jQuery or AJAX to check if there are:
1) a pdf
2) and an mp4
files in a folder?
I know the file names, if that is useful.

thanks in advance
1 Solution
Dave BaldwinFixer of ProblemsCommented:
You would have to have a program on the server that you contact that can check to see if the files are there.  You can't check anything on the user's local machine.
badwolfffAuthor Commented:
At present the site is on localhost
and once it works I will transfer it to a server.
Can it be done?
badwolfffAuthor Commented:
And if so, how?
thanks again for replying
Of course it can be done on the server.  The scripting is trivial in any commonly used server side scripting language.

Chris StanyonCommented:
As has already been said, you need a program/script sat server-side - something like PHP or ASP. You will then code your javascript to call that file, which in turn will read the folder and check for the files and spit out some kind of result - TRUE / FALSE etc. which is returned to your Javascript.

PHP has a function called file_exists() - returns a BOOLEAN value,  so your script mught be as simple as:

<?php echo file_exists('somefile.mp4'); ?>

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now