What exactly is the difference between accessing a file through HTML (e.g. <img src="xxx.jpg">
) or JavaScript, and using PHP to read a file. The file is still just on the server in both cases, isn't it?
What makes using PHP to access the server's file system different to someone just typing in the URL of the file (provided they know what it is)?
For static files like (images, HTML, etc) there is no difference, if you directly enter the file URI or read it internally and print the buffer through PHP (at this case the file URI will change for sure).
For dynamic files (PHP files), the same concept is true, if you enter the file URI directly you will get the output of that file, and if you read it internally (There are two types: include and read its source). but in most cases, PHP files are designed for execution not for printing the source, therefore, in both cases:
javascript is client side and runs in the browser.
php is server side and runs in the server.
note that there are now server side javascript interpreters like node.js or phantom.js
In the two cases you mentioned the file is on the server. If the file is static such as images, you can have its URL directly in the HTML.
In some cases you need to to have a dynamic URL for the content, for example a download service that generates a temporary URL for the content after authenticating the user. In such case you would serve the file using PHP since you do not have a fixed URL for the content
Like you are saying, php might really access the FILE SYSTEM, while a client just can access files the Server handles to them.