-2

I have this php code:

move_uploaded_file($_POST["filelocation"], "dock/images/".explode("upload/",$_POST["filelocation"])[1]);
putindb();

And the putindb function works fine, I don't get any error, but the file isn't copied. How can i see what error is behind this? Or how can I resolve this?

korte alma
  • 59
  • 6

1 Answers1

1

Use the $_FILES superglobal to get the file paths $_FILES['nameOfFileInputField']['tmp_name'] that will give you the path where the file is.

In your form you should have something like:

<form method="POST" action="whatever.php">
    <input type="file" name="nameOfFileInputField" />
</form>

The type of the input field should be file.

chinloyal
  • 1,023
  • 14
  • 42
  • An example of the code edit required might help.... – Martin Feb 18 '18 at 17:10
  • But this isn't in a form, I don't get file upload, I just have to move files to other directory. – korte alma Feb 18 '18 at 17:13
  • @kortealma Yeah, when you move an uploaded file, you're not dealing with the `POST` array, you're working with the `$_FILES` superglobal, which has a path to the temporary file that stores the contents of a given field in the upload. This is what you need to move. I would also whitelist the path to move it to. – Jared Farrish Feb 18 '18 at 17:52
  • @JaredFarrish but then I don't have `nameOfFileInputField` how can I use than `$_FILES`? – korte alma Feb 18 '18 at 18:01
  • I have it but not this script makes the form upload. This script only have to move the file to other directory, this is used by an other page where isn't any file upload, just want to use the uploaded files. The files might be uploaded other time. – korte alma Feb 18 '18 at 18:13
  • You can't use `move_uploaded_file()` function to move files in a directory. That ounly moves uploaded files, as the name suggests. You can try this -> https://stackoverflow.com/questions/19139434/php-move-a-file-into-a-different-folder-on-the-server – chinloyal Feb 18 '18 at 18:19