以下是给定的代码。我想在上传之前重命名该文件。提交时显示错误:未定义的索引。
if($_FILES['FPScreenShot']['name']==true)
{
$SPPic = ($_FILES['FPScreenShot']['name']);
$curTime = time();
$NewPriorPic = "prior";
$NewPriorPic = $NewPriorPic.$SGeiNo;
$NewPriorPic = $NewPriorPic.$SSurgDt;
$NewPriorPic = $NewPriorPic.$curTime;
move_uploaded_file($_FILES['FPScreenShot']['tmp_name'] , "upload_pictures/".$_FILES['$NewPriorPic']['name']);
}
else
{
$SPPic = "NIL";
}
答案 0 :(得分:1)
我觉得你把这条线搞砸了一点:
(你忘记了开始引用)
move_uploaded_file($_FILES['FPScreenShot']['tmp_name'] , upload_pictures/".$_FILES['$NewPriorPic']['name']);
所以改成它:
move_uploaded_file($_FILES['FPScreenShot']['tmp_name'] , "upload_pictures/" . $_FILES[$NewPriorPic]['name']);
答案 1 :(得分:0)
您的代码中存在一些语法错误,您的逻辑似乎很难混淆您尝试实现的内容,但您可以尝试这样做:
<?php
if($_FILES['FPScreenShot']['name']) {
$SPPic = ($_FILES['FPScreenShot']['name']);
$curTime = time();
$NewPriorPic = "prior";
//Add aditional details to the file name
$NewPriorPic .= $SGeiNo;
$NewPriorPic .= $SSurgDt;
$NewPriorPic .= $curTime;
//Try to move uploaded file
if (move_uploaded_file($_FILES['FPScreenShot']['tmp_name'] , "upload_pictures/".$_FILES[$NewPriorPic]['name'])) {
echo "File successfully uploaded.";
}
else {
echo "Error while uploading the file.";
}
}
else {
$SPPic = "NIL";
}
答案 2 :(得分:0)
解决。如有需要,供将来参考。
if($_FILES['FPScreenShot']['name']==true)
{
$SPPic = ($_FILES['FPScreenShot']['name']);
$ext = pathinfo($SPPic, PATHINFO_EXTENSION);
$curTime = time();
$NewPriorPic = "prior";
$NewPriorPic = $NewPriorPic.$SGeiNo;
$NewPriorPic = $NewPriorPic.$SSurgDt;
$NewPriorPic = $NewPriorPic.$curTime;
$NewPriorPic = $NewPriorPic.".".$ext;
$location = "upload_pictures/";
move_uploaded_file($_FILES['FPScreenShot']['tmp_name'], $location.$NewPriorPic);
}