- Home /
WWW and File.Exists to check new file on server
I am aware that we can use WWW class to read the content of a specific file. But I wonder, is there a way to find out if there is a new file put on server, and read that one instead. So, I figured out using File.Exists from System.IO. Could someone point me to a tutorial how these File.Exists and WWW to check a new file on server?
Answer by Bunny83 · Jul 18, 2013 at 05:37 AM
No, File.Exists only works with files on a local connected filesystem. Files on a server always have to be requested via HTTP. What you would need is a HEAD request but unfortunately the WWW class that comes with Unity only supports GET and POST requests.
You have two options:
Use a different class for your webrequest that supports the HEAD method. This might help
If your webserver supports PHP you can create a PHP file that returns what files are available on your server.
Not all web servers support HEAD for all URLs. Often dynamic content URLs or temporal URLs won't support it. So the most robust way is the second one.
I'm not a php programmer, but the script should be very easy. All you need is this function:
http://php.net/manual/en/function.scandir.php
What format you use to return them is up to you. You could simple join (implode afaik) the array with a delimiter like | or ,
I would probably go with a json response. So it would be a one-liner like this i guess:
<?php echo json_encode(scandir("your directory on your server")); ?>
This should return all files in the given folder in a json array.
Your answer
![](https://koobas.hobune.stream/wayback/20220613110338im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Web player file access 1 Answer
WWW file:// protocol to list a directory 1 Answer
Using WWW to load all files in StreamingAssets directory 2 Answers
Is there a way to encrypt/lock a File.CreateText file? (its my highscore) 1 Answer