How to Implement pseudo-static node. js-PHP

Source: Internet
Author: User
Pipeline is a file name. Simply put, how can we implement this pseudo-static state? As long as the index. php file receives the xx. xxx parameter, we can {generation... ask how to implement it, such

Https://www.xxx.com/img/1015308c0ebce716.jpg

Where1015308c0ebce716.jpgIs a file name

To put it simply, how can we implement this pseudo-static state? As long as the index. php file receives the xx. xxx parameter?

$ _ SERVER [ORIG_PATH_INFO] // use this?

Taking into account a lot of files, such slice storage is definitely not easy to manage.

Therefore, we want to use a unique id as the file name during the upload process and store it in different folders at the same time.

Reply content:

How to implement it, such

Https://www.xxx.com/img/1015308c0ebce716.jpg

Where1015308c0ebce716.jpgIs a file name

To put it simply, how can we implement this pseudo-static state? As long as the index. php file receives the xx. xxx parameter?

$ _ SERVER [ORIG_PATH_INFO] // use this?

Taking into account a lot of files, such slice storage is definitely not easy to manage.

Therefore, we want to use a unique id as the file name during the upload process and store it in different folders at the same time.

"Pseudo-static" is actually a pseudo concept. In fact, through some technology, the client (usually a browser) considers it to be accessing a "static" resource, as mentioned by the subject in the descriptionhttps://www.xxx.com/img/1015308c0ebce716.jpgIt is the "dynamic" content returned by a PHP script. To do this, at least the following conditions must be met:

  1. The URL looks like a static file.
  2. Content-TypeTell the browser that it is a static file. As mentioned in the JPEG imageimage/jpeg

Here we assume that PHP and nginx are used:

  1. Assume that/img/1015308c0ebce716.jpgIt is a PHP file, and nginx is told to handle the file in PHP, and the problem is solved. Obviously, this is not a very good idea. This design not only makes us confused, but limits the architecture of the application itself, and the passing of parameters is obviously hard. If we can access/img/1015308c0ebce716.jpgWhen the request is sent to a PHP script, and part of the URL can be taken as a parameter, the problem is solved elegantly. In fact, nginx's ngx_http_rewrite_module can do this. (Apache can use mod_rewrite ). For example, assume that/img/1015308c0ebce716.jpgThe corresponding processing script is/index.php?mod=image&id=1015308c0ebce716AndidAs a parameter, so:

    nginxserver {    root /path/to/app;    rewrite ^/img/([a-z\d]+)\.jpg$ /index.php?mod=image&id=$1 last;    location /index.php {        ...        ...    }}
  2. Solve the previous problem, and this is a good solution. If it is a PHP script, use it directly here.header('Content-Type: image/jpeg')Okay.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.