Can’t upload images in a folder through php

  html, php

I read lots of duplicate about this question and yet I didn’t find an answer. I just have to upload an image through PHP. After submitting the form I can see the name of the picture in my database but not in the IMAGES folder I created. Someone as some solution? Thanks in advance

The root folder:

hyperink
|_____IMAGES
|_____create.php

create.php

<?php
  include 'functions.php';

  $msg = '';

  //INSERT
  if(isset($_POST['submit']))
  {
    // Posted Values
    $title=$_POST['title'];
    $category=$_POST['category'];
    $main=$_POST['main'];
    $imageName=$_FILES['immagine']['name'];
    $imageTmp = $_FILES['immagine']['tmp_name'];

    $target = 'IMAGES/' . $imageName;
    move_uploaded_file($imageTmp, $target);

    // Query for Insertion
    $sql="INSERT INTO post (title, category, main, image) VALUES (?,?,?,?)";
    //Prepare Query for Execution
    $stmt = $pdo->prepare($sql);

    // Query Execution
    $stmt->execute([$title, $category, $main, $image]);
    $msg = "Added Successfully";
  }


?>

<div class="box_create">
        <form action="create.php" method="post" id="form_create" enctype="multipart/form-data">
          <label class="labels_create">Titolo del Articolo</label>
          <input type="text" name="title" id="title" class="inputs_create">
          <label class="labels_create">Categoria</label>
          <input type="text" name="category" id="cat" class="inputs_create">
          <label class="labels_create">Contenuto del Articolo</label>
          <textarea id="main" name="main" rows="5" cols="50" class="inputs_create_contenuto"></textarea>
          <input type="file" id="immagine" name="immagine" class="inputs_create_file" accept="image/*">
          <input type="submit" name="submit" value="Crea nuovo articolo" class="btn_create">
        </form>
      </div>

Source: Ask PHP

LEAVE A COMMENT