jmbockhorst
jmbockhorst

Reputation: 88

Moving uploaded files error

Whats wrong with this code?

<?php
move_uploaded_file($_FILES['file']['tmp_name']."picture/".$_FILES['file']['name']);
?>

<form action='' method='post' enctype='multipart/form-data'>
<input type='file' name='file'>
<input type='submit' name='submit' value='Upload'>
</form>

I'm getting this error: Warning: move_uploaded_file() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\social\profile.php on line 3

Upvotes: 0

Views: 2231

Answers (2)

Sharikov Vladislav
Sharikov Vladislav

Reputation: 7269

See the docs. Move-uploaded-file function have to pass 2 parameters:

string $filename
string $destination

Also, I assume you have mistake in your function. There are 2 params, but you concat them, not separate. Use , insteald of . before "/pictures/":

move_uploaded_file($_FILES['file']['tmp_name'], "picture/".$_FILES['file']['name']);

This will work.

Upvotes: 1

Chris Brown
Chris Brown

Reputation: 4635

Your full stop before "picture/" should be a comma to separate the parameters, guessing a typo

<?php
    move_uploaded_file($_FILES['file']['tmp_name'], "picture/".$_FILES['file']['name']);
?>

<form action='' method='post' enctype='multipart/form-data'>
    <input type='file' name='file'>
    <input type='submit' name='submit' value='Upload'>
</form>

Upvotes: 0

Related Questions