Why does PHP store uploaded files in a temporary location and what is the benefit?

前端 未结 3 712
别跟我提以往
别跟我提以往 2021-01-31 01:08

Okay I\'m totally new in this field and going through some tutorials and I found that while uploading files in PHP it stores them in a temporary location.

$file         


        
3条回答
  •  无人及你
    2021-01-31 02:10

    Two additional reasons:

    1. If you decide not to accept the file for some reason, it's stored in a temporary location and presumably will be automatically deleted at some point.

    2. Security. Let's say PHP was set to upload to a web-accessible directory like /images. Someone could upload some sort of hacking file and then execute it. By putting files in a temporary directory first (which will usually not be web-accessible), PHP lets you examine the file first. For instance, by processing images to remove any comments that could contain PHP code.

提交回复
热议问题