How to take the name of the picture from the form and upload the picture to another file

$servername = 'localhost'; $username = 'root'; $password = ''; $dbname = 'shop'; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $name = ($_GET['name']); $description = ($_GET['description']); $price = ($_GET['price']); $category = ($_GET['category']); if ($stmt = $conn->prepare("INSERT INTO products (name, description, price, category) VALUES (?, ?, ?, ?)")) { // Bind the variables to the parameter as strings. $stmt->bind_param("ssss", $name, $description, $price, $category); // Execute the statement. $stmt->execute(); // Close the prepared statement. $stmt->close(); echo "ok"; } ?> 

    1 answer 1

    The data about the loaded pictures is stored in the $ _FILES array. http://php.net/manual/ru/features.file-upload.post-method.php

    If the file field is named userfile, then

     $_FILES['userfile']['name'] 

    This is the original file name.

    In order to save the file to the server, it must be copied somewhere from a temporary file.

     $_FILES['userfile']['tmp_name'] 
    • Can you give a specific example? - Hayk Harutyunyan
    • Of course. Above, I gave a link to the documentation, everything is described there in detail. Here is an example of saving the file move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); - Ivan Bolnikh