-1
<form enctype="multipart/form-data" name="frmUpload" method="post" action="">
    Select a file that you want to upload:<br />
    <input type="file" name="users"><br /><br />
    <input type="submit" name="submit" value="Upload File">
</form>
</body>
</html>
<html>
<head>
<title>File Uploader</title>
</head>
<body>
<?PHP
if(@$_POST['submit'] == "Upload File") {
    if ($_FILES["users"]["error"] > 0) {
        echo "<strong>Sorry, the file could not upload.</strong><br />";
        echo "Error message: " . $_FILES["users"]["error"];
    } else {
        echo "File to upload: " . $_FILES["users"]["name"] . "<br />";
        echo "File type: " . $_FILES["users"]["type"] . "<br />";
        echo "File size: " . ( $_FILES["users"]["size"] / 1024) . " Kb<br />";
        echo "Temp file name: " . $_FILES["users"]["tmp_name"] . "<br /><br />";
        if (file_exists($_FILES["users"]["name"])) {
            echo "<strong>" . $_FILES["users"]["name"] . " already exists.</strong>";
        } else {
            if(@move_uploaded_file($_FILES["users"]["tmp_name"], $_FILES["users"]["name"])) {
                echo "<strong>Saved as: " . $_FILES["users"]["name"] . "</strong>";
            } else {
                echo "<strong>File: " . $_FILES["users"]["name"] . " was not uploaded!</strong>";
            }
        }
    }
    echo "<br /><br />";
}
?>

that's the code I would like to save at a certain path. But I appear to be getting errors I am relatively new to coding so please don't go in on me if you see lots of mistakes many thanks. Also, I am a student learning PHP so, please help me it would be much appreciated please educate me

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • What errors are you getting? – aynber Jan 19 '21 at 13:46
  • its not an error i am trying to get it to upload the file in a subfolder but cant seem to get it working – Ahmar Safi Jan 19 '21 at 13:47
  • 4
    Please give us a clear problem description. _I appear to be getting errors_ is not very helpful - either you do or you don't get errors. What do you expect to happen, what is actually happening? Do you have error reporting enabled? – berend Jan 19 '21 at 13:49
  • If you are using the `@` error supression character, you are shouting that you are doing something wrong. If you get errors fix them dont pretend they dont exist – RiggsFolly Jan 19 '21 at 13:51
  • sorry first time using this – Ahmar Safi Jan 19 '21 at 13:51
  • Is that 2 different files you are showing us there? – RiggsFolly Jan 19 '21 at 13:52
  • The `@` symbol suppresses any errors for that line of code, so it's not surprising you aren't getting any errors. – GrumpyCrouton Jan 19 '21 at 13:53
  • would i need to remove this to show the errors – Ahmar Safi Jan 19 '21 at 13:54
  • also its one file – Ahmar Safi Jan 19 '21 at 13:54
  • Add [error reporting](http://stackoverflow.com/questions/845021/) to the top of your file(s) _while testing_ right after your opening PHP tag for example. Even if you are developing on a server configured as LIVE you will now see any errors. ` – RiggsFolly Jan 19 '21 at 13:56
  • Better test and will allow you to lose the `@` would be `if(isset($_POST['submit']) && $_POST['submit'] == "Upload File") {` Check it exists before using it – RiggsFolly Jan 19 '21 at 13:58
  • thank you i no longer need the @ but am unable to put it in a path so that the file gets uploaded there – Ahmar Safi Jan 19 '21 at 14:03
  • Parse error: syntax error, unexpected '{' in C:\Users\Ali\Desktop\USBWebserver v8.5\8.5\root\Fileupload.php on line 29 this is the error I have got – Ahmar Safi Jan 19 '21 at 14:13
  • Does this answer your question? [Reference — What does this symbol mean in PHP?](https://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – Nico Haase Jan 19 '21 at 21:45
  • i do not know how to add a path file /foler to my code – Ahmar Safi Jan 19 '21 at 23:49
  • Parse error: syntax error, unexpected T_ECHO in C:\Users\Ali\Desktop\USBWebserver v8.5\8.5\root\Fileupload.php on line 30 – Ahmar Safi Jan 20 '21 at 08:55

1 Answers1

0

You didn't choose path where to move your file, must be like

move_uploaded_file($_FILES["users"]["tmp_name"],"Your path". $_FILES["users"]["name"])
V.D.
  • 1,215
  • 1
  • 7
  • 17
  • how would i put my path in as I have done it like this if(@move_uploaded_file($_FILES["users"]["tmp_name"],"USBWebserver v8.5\8.5\root\Pictures". $_FILES["users"]["name"])) { – Ahmar Safi Jan 19 '21 at 13:59