简体   繁体   English

读取客户端和服务器端文件的区别

[英]Difference between reading files client-side and server-side

What exactly is the difference between accessing a file through HTML (eg <img src="xxx.jpg"> ) or JavaScript, and using PHP to read a file. 通过HTML(例如<img src="xxx.jpg"> )或JavaScript访问文件与使用PHP读取文件之间的区别到底是什么? 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)? 是什么使使用PHP访问服务器的文件系统与仅输入文件URL的用户有所不同(前提是他们知道文件的含义)?

javascript is client side and runs in the browser. javascript是客户端,可在浏览器中运行。

php is server side and runs in the server. php是服务器端,在服务器中运行。

note that there are now server side javascript interpreters like node.js or phantom.js 请注意,现在有服务器端javascript解释器,例如node.js或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. 如果文件是静态文件(例如图像),则可以直接在HTML中使用其URL。

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. 在某些情况下,您需要为内容提供一个动态URL ,例如,下载服务在对用户进行身份验证后为该内容生成一个临时URL。 In such case you would serve the file using PHP since you do not have a fixed URL for the content 在这种情况下,您将使用PHP提供文件,因为您没有固定的内容URL

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). 对于静态文件(图像,HTML等),如果直接输入文件URI或在内部读取文件并通过PHP打印缓冲区(在这种情况下,文件URI肯定会更改),则没有区别。

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). 对于动态文件(PHP文件),同样的概念也适用,如果直接输入文件URI,则将获得该文件的输出,并且在内部读取该文件(有两种类型:包括和读取其源代码)。 but in most cases, PHP files are designed for execution not for printing the source, therefore, in both cases: 但在大多数情况下,PHP文件是为执行而设计的,而不是为打印源而设计的,因此,在两种情况下:

  • When you try to read static files by PHP its just resource wasting if there is no need to use PHP. 当您尝试通过PHP读取静态文件时,如果不需要使用PHP,则只会浪费资源。

就像您说的那样,php可能实际上访问了文件系统,而客户端只能访问服务器处理给它们的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 客户端和服务器端编程有什么区别? - What is the difference between client-side and server-side programming? “客户端JavaScript”,“服务器端JavaScript”和“CoreJavaScript”之间的区别 - Difference between “Client-Side JavaScript”, “Server-side JavaScript” and “CoreJavaScript” 客户端和服务器端javascript中“ this”的值之间的差异 - Difference between value of 'this' in client-side vs server-side javascript 在客户端和服务器端之间发送信息和变量 - Sending info and variables between Client-Side and Server-Side 客户端或服务器端处理? - Client-side or server-side processing? 服务器端和客户端JavaScript - Server-side and client-side JavaScript 客户端还是服务器端框架? - Client-side or server-side framework? 如何填补ASP.NET webforms中服务器端和客户端之间的空白? - How to fill the gap between server-side and client-side in ASP.NET webforms? 如何使用 JavaScript 正确编码服务器端和客户端之间的交换数据? - How to correctly code an interchange data between server-side and client-side using JavaScript? 需要在HTML + JavaScript的客户端和Java / C ++的服务器端程序之间进行通信 - Need to communicate between Client-side in HTML+JavaScript and Server-side program in Java/C++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM