php will download the file instead of downloading the hyperlink, which can reduce hotlinking! Give the file to the browser and let the browser download it. Take txt type as an example To avoid opening the txt file directly in the browser, you can rename the txt file to a file that the browser does not recognize (such as rar). In this case, because the browser cannot recognize the rar type file, the user can only download it. The above methods are sometimes very inapplicable. We use another method to set the format of the document through the header information of the php file to achieve the purpose of click download. Example:
Instructions: The first header function sets the value of Content-Type to application/force-download; The second header function sets the file to be downloaded. Note that filename here is a file name that does not include a path. The value of filename will be the file name in the dialog box that pops up after clicking download. If there is a path, the file name in the dialog box that pops up is unknown; Finally, through the readfile function, the file stream is output to the browser to realize the download of the txt file. |