2

In my PHP web page I have a file type input in a form and when I submit it I can get the file name which was uploaded with $_POST['upload'] but if I use $_FILES['upload']['tmp_name'] it gives nothing -- why? How can I use $_FILES to get the file to attach it to my email?

Ghopper21
  • 10,287
  • 10
  • 63
  • 92
Jamol
  • 3,768
  • 8
  • 45
  • 68
  • 1
    have you set the form `enctype` to `multipart/form-data`? See http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2 – Geoffrey Aug 05 '12 at 12:49

2 Answers2

9

You got nothing when you use $_FILE because you didn't use the enctype attribute on your form. Check how to use it here.

Ghopper21
  • 10,287
  • 10
  • 63
  • 92
user1577291
  • 366
  • 1
  • 3
  • 15
5
<form method="POST"  action=#" enctype="multipart/form-data">
</form>

$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
if(is_uploaded_file($tmp_path))
{
 if(!copy($tmp_path,$path_of_uploaded_file))
 {
    $errors .= '\n error while copying the uploaded file';
}

Or for detailed info go here Go Here

Community
  • 1
  • 1
Fahid Mohammad
  • 910
  • 3
  • 17
  • 47