$ _FILES [ “文件”] [ “tmp_name的值”]

时间:2012-06-15 05:08:58

标签: php file-upload

我使用文件上传表单将文件上传到我的服务器。然后我echo $_FILES["file"]["tmp_name"]但它返回给我一个似乎不存在的位置。例如/ tmp / phpBparj4是输出,但我的/ tmp文件夹中没有这样的文件/文件夹。我还检查了文件夹的适当权限

我的实际问题是move_uploaded_file($_FILES["file"]["tmp_name"],$target);,它没有将上传的文件移动到目标位置。我也试过move_uploaded_file($_FILES["file"]["tmp_name"].$file_name,$target);

1 个答案:

答案 0 :(得分:2)

我不确定我是否理解正确,但为什么不能指定文件夹位置?即“。

//set the right path from the server perspective
$article_file_path = $_SERVER['DOCUMENT_ROOT'];

// you should check for the file if it is/ or not already there (something like this)
if (!file_exists($article_file_path ."/your_folder/file_subfolder/". $_FILES["my_file"]["name"]))
      { do something.....


// then make your script upload the file exactly where you want it
move_uploaded_file($_FILES["my_file"]["tmp_name"],          
      $article_file_path ."/your_folder/file_subfolder/".$_FILES["my_file"]["name"]);

// and the download link to the uploaded file would be something like this:
echo "http://". $_SERVER["HTTP_HOST"] . "/files-article/".$_FILES["my_file"]["name"]";