-1

so i have a form that will let users upload certain files to my website (server), and I've been trying to figure out a way to upload the file the user has submitted (and all of its contents) to my server successfully.

Here is what I've tried so far:

(My form)

  <form action="index.php" method="post">
    Select File:<br/>
    <input type="file" name="file" id="fileID" accept=".ff"><br/>
    <input type="submit" name="submitfile" value="Upload"/>
  </form>

(My PHP)

if(isset($_POST['submitfile']))
{
    $GetFileextension=$_POST['file'];
    if(end(explode('.', $GetFileextension))=="ff")
    {
        $usrU = fopen($_POST['file'], "w"); //Attempt to upload file
    }
    else
    {
        echo "Error: unsupported file type"; //File type is unsupported
    }
}

The problem is that all this will do is upload the file to my server but it doesn't contain any of the file contents.

For example if i had a file name something like example.ff and i use the above script to try to upload the file, all it will do is create a file in my server named example.ff BUT the file in my server will not contain example.ff original contents.

What am i doing wrong? Am i uploading the file incorrectly or something?

RevTech
  • 35
  • 2
  • 9

1 Answers1

0

Firstly do one thing

<form action="index.php" method="post" enctype="multipart/form-data">

Then you have to _POST your file like

$file=$_FILES['file']['name'];    

And then for upload file in folder

move_uploaded_file($_FILES['file']['tmp_name'],"path/".$file)
Jay Doshi
  • 666
  • 1
  • 5
  • 16