修复了upload.php脚本的文件名

时间:2013-02-19 20:15:25

标签: php xml file-upload upload

我正在尝试将XML文件上传到服务器,此文件名为data.xml。每次访问数据时都会被覆盖。

我的疑问是如何将文件名设置为固定名称,并使用.xml扩展名作为扩展名过滤器?我想将文件放在与upload.php相同的文件夹中。

这是我到目前为止所尝试的内容:

<?php

$target_path = "uploads/";

$target_path = $target_path . basename($_FILES['uploadedfile']['name']);

if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ", basename($_FILES['uploadedfile']['name']), " has been uploaded";
} else {
    echo "There was an error uploading the file, please try again!";
}

1 个答案:

答案 0 :(得分:0)

你试过了吗?

<?
$target_path = "uploads/";

$target_path = $target_path . 'data.xml'; 

 if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
" has been uploaded";
 } else{
 echo "There was an error uploading the file, please try again!";
 }
?>