I am working on a website and I want the user to upload files or images to the website. So I am finding a way to do that. I look into and it said that I needed to use the function move_uploaded_file(). I wrote the code very much like it was on the example (changing the information), however, it wouldn't work. Please help me, I'm new at these. Here's what I've done so far:

1. index.php

<!DOCTYPE html>
   <form action="upload_file.php" method="POST" enctype="multipart/form-data">
      <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
      <input type="file"name="file">
      <input type="submit">

2. upload_file.php

    $move = "/xampp/htdocs/project/uploads/";
    echo $_FILES["file"]['name']."<br>";
    echo $_FILES["file"]['tmp_name']."<br>";
    echo $_FILES["file"]['size']."<br>";
    echo $_FILES['file']['error']."<br>";
    move_uploaded_file($_FILES['file']['name'], $move);


php file file-upload 
1 Answers

With PHP, it is easy to upload files to the server.

In any case, easily comes risk, so regularly be careful when permitting file upload!


    $upload_folder = "/xampp/htdocs/project/uploads/"; // path to upload folder
    $file_location = $upload_folder . basename($_FILES["fileToUpload"]["name"]);
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $file_location)) {
       echo "The file has been uploaded.";
    } else {
       echo "Sorry, there was an error uploading your file.";


answered Nov 26

Login and Submit Your Answer
Browse other questions tagged  php  file  file-upload or ask your own question.