Upload unity game to server and read file from local disk

Hi, I’ve recently uploaded an unity game to a web server which access to a txt file in my local disk, the problem is if I run the game outside the server (double click on the web page), it works, but if I try to access it using localhost/…bla bla bla, it doesn’t. Can anyone get me a hand with this ?

Webpages don’t have any access to the local file system. Actually they don’t have access to anything on the clients PC. Websites run inside a security sandbox. There are even a couple of browsers who doesn’t allow access to local files even when run from the local file system.

However there are new APIs that newer browsers support which enables users to give access to specific files. For example FileList. However some APIs are quite new and not yet standardised / supported by all browsers.

In the past the only way to get access to a user file was to provide an upload form on the webpage, let the user select the files and send them over to the server. The webpage then would download the file from the server back to the client. Those new APIs allow direct access to those files without sending them over the net.

Though keep in mind that you still can only access files that the user has selected manually. There is no way to just use a file path and access a random file on the clients machine.

If the file is part of your game, you should actually place it on the server as well. A website can load any kind of file / data from the server where it’s hosted.