-1

Can someone tell me what is wrong with this line of code? I am getting an error (yet the the page still functions properly despite the error)

Error:

"Notice: Undefined index: picture in C:\wamp\www\pplogin\members.php on line 180"

Here is the code:

179  $target = "user_images/fs/";
180  $target = $target . basename($_FILES['picture']['name']);

Like I said earlier despite the error the image gets uploaded to the destination and the image name is saved to my MySQL database.

I've been scratching my head for a while now...

jeroen
  • 91,079
  • 21
  • 114
  • 132
Dan Graves
  • 347
  • 2
  • 4
  • 14

2 Answers2

3
$target = !empty($_FILES['picture']['name']) ? $target.basename($_FILES['picture']['name']) : false;
Sam
  • 2,950
  • 1
  • 18
  • 26
1

A file with id

picture

doesn't exist.

Use

isset()

to make sure It's set.

You can also use the ternary operator:

$img = isset($_FILES['picture']) ? $_FILES['picture'] : null;

Or something like that :)

Jonast92
  • 4,964
  • 1
  • 18
  • 32