Reputation: 836
Below is the given code. I want to renamen the file before uploading. On submitting it is showing error: Undefined index.
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";
}
Upvotes: 2
Views: 142
Reputation: 836
Solved. For future reference, if anyone needed.
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);
}
Upvotes: 0
Reputation: 59691
I think you messed this line a little bit up:
(You forgot the start quote)
move_uploaded_file($_FILES['FPScreenShot']['tmp_name'] , upload_pictures/".$_FILES['$NewPriorPic']['name']);
So change it to this:
move_uploaded_file($_FILES['FPScreenShot']['tmp_name'] , "upload_pictures/" . $_FILES[$NewPriorPic]['name']);
Upvotes: 1
Reputation: 31839
There are some syntax errors in your code and your logic seems to be little confusing of what you are trying to achieve, but you can try this:
<?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";
}
Upvotes: 0