我正在运行一个 PHP 脚本来从 HTML 表单上传文件,重命名它们并将它们放在我的服务器上。它正在上传和重命名,但是现在每个文件名都以“Array”一词开头,
即:ArrayTest Document v1.0.pdf
我相当确信它不是我的$newfn
变量,因为我在表格中显示它并且它没有显示出来。
//This gets all the other information from the form
$name=$_POST['docname'];
$version=$_POST['docver'];
$date=$_POST['docdate'];
$type=$_POST['doctype'];
$author=$_POST['docauth'];
$file=$_FILES['uploaded']['name'];
//target directory is assigned
$target = $directory;
$target = $target . basename($file) ;
//grab file extension
$filetypes = array(
'image/png' => '.png',
'image/gif' => '.gif',
'image/jpeg' => '.jpg',
'image/bmp' => '.bmp',
'application/pdf' => '.pdf');
$ext = $filetypes[$_FILES['uploaded']['type']];
//generate new filename variable "name v??.xxx"
$newfn = $name . ' ' . 'v' . $version . $ext;
//Check to see if file exists
if (file_exists($directory . $file))
{
echo $_FILES["uploaded"]["name"] . " already exists. ";
}
else
{
//if its a new file, change name and upload
if (move_uploaded_file($_FILES["uploaded"]["tmp_name"],
$directory . $_FILES["uploaded"] . $newfn))
{
echo "The file ". basename($file). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
我觉得它与命令$FILES['uploaded']
中的我的部分有关move_uploaded_file
。我试过谷歌搜索,但只要我提到“数组”,我的谷歌搜索结果就完全不同了。
好的,多亏了下面我解决了它。对于将来的任何人,我删除了整个$_FILES
数组,因此代码读取为
//if its a new file, change name and upload
if (move_uploaded_file($_FILES["uploaded"]["tmp_name"],
$directory . $newfn))
现在所有内容都以正确的名称结构上传。谢谢。