0

Hi Hi trying to upload a file via a form move it to another folder and then print its name. But doesnt work don't know why.

<form method="post" action='exercice.php' id="form1">
        <input type="file" name="files" id="files" onChange="submitForm();">            
</form>
<?php

if (isset($_FILES['files']))
{

    move_uploaded_file($_FILES['files']['tmp_name'], "uploaded/");
    echo $_FILES['files']['name'];
}


?>
stephan lemaitre
  • 85
  • 1
  • 1
  • 9

2 Answers2

3

form missing:

 enctype="multipart/form-data"

ref: spec

jancha
  • 4,916
  • 1
  • 24
  • 39
  • thanks but now my folder did not move to the specific folder don't know why – stephan lemaitre Jun 17 '13 at 23:54
  • you are trying to upload folder vs file? that is very badly supported feature and requires different backend. read this for more: http://stackoverflow.com/questions/254251/what-is-the-best-way-to-upload-a-folder-to-a-website – jancha Jun 19 '13 at 07:48
0
<form method="post" action='exercice.php' id="form1">
        <input type="file" name="files" id="files" onChange="submitForm();">            
</form>
<?php

if (isset($_FILES['files']))
{

    move_uploaded_file($_FILES['files']['tmp_name'], "uploaded/".$_FILES['files']['name']);
    echo $_FILES['files']['name'];
}

?>

You need to include the file name in the upload path, like shown above.

Also, where is your upload (ajax) code? Did isset($_FILES['files']) return true?

ekreutz
  • 26
  • 1