How to Implement PHP Pseudo static

  node.js, question

Ask for advice how to achieve, for example

among them1015308c0ebce716.jpgIt’s a file name

Simply put, how to realize this Pseudo static? As long as the file index.php receives the parameter

 //Use this?

Considering many files, such flaky storage is definitely not easy to manage.

Therefore, I want to use the unique id as the file name in the process of uploading. I want to store it in a different folder inside by time.

“Pseudo static” is actually a pseudo concept. In fact, it is a technology that makes the client (usually browser) think that it is accessing “static” resources, as mentioned by the subject in the description. the “dynamic” content returned by a PHP script, and in order to do this, at least several conditions need to be met:

  1. The URL looks like a static file
  2. Content-TypeTell the browser that it is a static file. For example, the JPEG image mentioned corresponds toimage/jpeg

Then one by one to solve, here we assume that PHP and nginx:

  1. If in the application program/img/1015308c0ebce716.jpgIt is a PHP file itself, and told nginx to leave it to PHP to handle when handling this file, and the problem was solved. Obviously, this is not a particularly good idea. This design not only makes us confused and limits the architecture of the application itself, but also the parameter transfer obviously becomes a hard nut to crack. So if we can visit/img/1015308c0ebce716.jpgAt the same time, give the request to a PHP script, and can take part of the URL as a parameter, the problem is solved gracefully. In fact, nginx’sngx_http_rewrite_moduleThis can be done. (apache can be usedmod_rewrite) 。 For example, suppose/img/1015308c0ebce716.jpgThe corresponding processing script is/index.php?mod=image&id=1015308c0ebce716, andidAs a parameter exists, then:

    nginxserver {
        root /path/to/app;
        rewrite ^/img/([a-z\d]加)\.jpg$ /index.php?mod=image&id=$1 last;
        location /index.php {
  2. After solving the previous problem, this is easy to handle. If it is a PHP script, use it directly here.header('Content-Type: image/jpeg')Just fine.

Finally, what the subject mentioned$_SERVER[ORIG_PATH_INFO]It can appear as a form of passing parameters to PHP scripts, and even as a part of the overall design and implementation of URL in architecture. Here you can refer to the implementation of ThinkPHP. ….