Isn't Using the basename function with $_FILES['userFile']['name'] Redundant?

后端 未结 3 1026
野性不改
野性不改 2021-01-01 06:15

According to the POST method uploads section of the PHP Manual, $_FILES[\'userfile\'][\'name\'] is the original name of the file on the client machine. Example

3条回答
  •  抹茶落季
    2021-01-01 06:40

    That is, using the basename function with $_FILES['userFile']['name'] seems rather redundant. Isn't it?

    No, first and foremost for security reasons as @Gumbo describes in his answer; secondly, because older versions of IE used to deliver the full path of the file on client side, like

    C:\Documents and Settings\Username\Desktop\Image_cropped.jpg
    

    that behaviour stopped as recently as IE8. From this MSDN blog entry discovered via this SO question:

    File Upload control

    Additionally, the “Include local directory path when uploading files” URLAction has been set to "Disable" for the Internet Zone. This change prevents leakage of potentially sensitive local file-system information to the Internet. For instance, rather than submitting the full path C:\users\ericlaw\documents\secret\image.png, Internet Explorer 8 will now submit only the filename image.png.

提交回复
热议问题