How to define the file storage location in PHP FILE UPLOAD

流过昼夜 提交于 2020-02-15 10:14:28

问题


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?

<?php
if ($_FILES["file"]["error"] > 0)
{
    echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
    echo "Upload:    " . $_FILES["file"]["name"] . "<br />";
    echo "Type:      " . $_FILES["file"]["type"] . "<br />";
    echo "Size:      " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Stored in: " . $_FILES["file"]["C:\xampp\htdocs\tmp"];
}

回答1:


$_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.




回答2:


well the code you posted isn't moving any file. You miss

move_uploaded_file ( $_FILES["file"]["tmp_name"][$key], 'C:\xampp\htdocs\tmp\new_file.txt' );

http://php.net/manual/en/function.move-uploaded-file.php



来源:https://stackoverflow.com/questions/10241658/how-to-define-the-file-storage-location-in-php-file-upload

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!