【问题标题】:Fixed file name for upload.php script [closed]修复了upload.php脚本的文件名[关闭]
【发布时间】:2013-02-04 16:02:16
【问题描述】:

我正在尝试将 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!";
}

【问题讨论】:

  • 为什么要固定文件名?
  • 此文件稍后将被另一个系统访问。每次用户点击时都会读取该文件。
  • 你有什么问题?

标签: php xml file-upload upload


【解决方案1】:

你试过了吗:

<?
$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!";
 }
?>

【讨论】:

  • basename($_FILES['uploadedfile']['name']) 的作用是什么?
  • @DesperateLearner 您可以查看basename 的手册。这些东西只是谷歌搜索而已。请在发布问题之前尝试在网络上找到答案。
猜你喜欢
  • 2014-08-01
  • 1970-01-01
  • 2016-11-07
  • 1970-01-01
  • 1970-01-01
  • 2020-01-07
  • 1970-01-01
  • 2014-04-15
  • 1970-01-01
相关资源
最近更新 更多