2

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";
        }
3
  • Your code contains syntax errors. Commented Dec 8, 2014 at 8:19
  • possible duplicate of Reference - What does this error mean in PHP? Commented Dec 8, 2014 at 8:19
  • Check your usage of quotes at the line starting with move_uploaded_file( Commented Dec 8, 2014 at 8:19

3 Answers 3

1

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']);
Sign up to request clarification or add additional context in comments.

2 Comments

quotes are there, may be during copy paste i messed it up. let me edit it in question.
@Sandhu Which error do you get exactly? and on which line?
0

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";
        }

Comments

0

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);
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.