0

I'm doing a react project and I just don't know if there is an error in the backend or frontent, so I tried the php file and I see that there is an error in it, so any advice please?

Checked php.ini and file_uploads=On

    <?php 

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {

        $target_dir = '/var/www/html/server/uploaded/products_images/';
        $target_file = $target_dir . basename($_FILES['files']['name']);


        if (move_uploaded_file($_FILES['files']['tmp_name'], $target_file)) {
            echo 'The file '. htmlspecialchars( basename( $_FILES['files']['name'])). ' has been uploaded.';
        } else {
            echo 'Sorry, there was an error uploading your file.';
        }

    }



?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form method='post' enctype='multipart/form-data' action='product_create_image_upload.php'>
        <input type='file' multiple accept='image/*' name='files'>
        <input type='submit' value='send'>
    </form>
</body>

</html>
  • Did you get `Sorry, there was an error uploading your file.` message or not? – aidinMC May 29 '22 at 10:44
  • Yes i get this message, so i think problem will be here? move_uploaded_file($_FILES['files[]']['tmp_name'], $target_file) –  May 29 '22 at 10:45
  • You should also do some proper debugging (like doing a `var_dump($_FILES)`) to see what you're actually getting. – M. Eriksson May 29 '22 at 10:53
  • Finally, there is no need for multiple images send now and need to send only one, because i have this for () in react and he will do it according to the number of images. So i need to solve this, because this dost save to server. move_uploaded_file –  May 29 '22 at 10:53

1 Answers1

0

Set products_images directory permission to 777

In Terminal

$ cd /var/www/html/server/uploaded
$ chmod -R 777 products_images
aidinMC
  • 1,415
  • 3
  • 18
  • 35