如何在PHP FILE UPLOAD中定义文件存储位置 [英] How to define the file storage location in PHP FILE UPLOAD

查看:168
本文介绍了如何在PHP FILE UPLOAD中定义文件存储位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的脚本中,我尝试上传文件到htdocs中的tmp文件夹,但文件没有移动到该位置。 ($ _FILES [file] [/ b]如何定义存储位置?

 <?php 
if error]> 0)
{
echoError:。 $ _FILES [file] [error]。 < br />;
}
else
{
echoUpload:。 $ _FILES [file] [name]。 < br />;
回显类型:。 $ _FILES [file] [type]。 < br />;
回声大小:。 ($ _FILES [file] [size] / 1024)。 Kb< br />;
回声存储在:。 $ _FILES [ 文件] [ C:\xampp\htdocs\tmp];

$ / code>


解决方案

$ _FILES [file] [C:\xampp\htdocs\tmp] 不应该存在,请改为:



< ($ _ FILES ['file'] ['tmp_name'],'/ path / to / your / upload / directory /')basename($ _ FILES ['file'] [ '名称']));

请记住,如果您使用此代码,则此代码不安全。 verbatim 因为它是),你需要验证MIME类型的文件( 正确 tools ),并至少清理 final 文件名。 $ b

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"];
}

解决方案

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

这篇关于如何在PHP FILE UPLOAD中定义文件存储位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆