Rename an uploaded file with PHP but keep the extension

后端 未结 7 1333
悲&欢浪女
悲&欢浪女 2020-12-04 20:24

I\'m using PHP to upload an image from a form to the server and want to rename the image lastname_firstname.[original extension]. I currently have:

move_upl         


        
7条回答
  •  自闭症患者
    2020-12-04 20:48

    Dont forget if you are allowing people to upload arbitrary files, without checking the, extension, they can perfectly well upload a .php file and execute code on your server ;)

    The .htaccess rules to deny php execution inside a certain folder is something like this (tailor for your setup)..

    AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
    Options -ExecCGI
    

    Put this into a .htaccess file into the folder where you are uploading files.

    Otherwise, just bear in mind that files may have more than one "." in them, and you should be golden.

提交回复
热议问题