How to define the file storage location in PHP FILE UPLOAD

后端 未结 2 1094
-上瘾入骨i
-上瘾入骨i 2021-01-22 14:17

In the following script I tried uploading file to tmp folder in htdocs but the file is not moving to that location. How do I define the storage location?



        
2条回答
  •  难免孤独
    2021-01-22 14:56

    $_FILES["file"]["C:\xampp\htdocs\tmp"] shouldn't exist, try instead:

    move_uploaded_file($_FILES['file']['tmp_name'], '/path/to/your/upload/directory/' . basename($_FILES['file']['name']));
    

    Bare in mind that this code is insecure if you use it verbatim (as it is), you need to validate the file mime type (with the proper tools) and sanitize the final file name at the very least.

提交回复
热议问题