jeudi 16 juin 2016

Image not uploading to web server

I am having some difficulty uploading an image to a folder on my web server. Here's my code:

HTML:

<form action="" method="POST" enctype="multipart/form-data">
    <input type="file" name="image">
    <input type="submit" value="Upload Image" name="upload">
</form>

PHP:

<?php
    if (isset($_POST["upload"])) {
        $name = $_FILES["image"]["name"];
        $type = $_FILES["image"]["type"];
        $size = $_FILES["image"]["size"];
        $temp = $_FILES["image"]["tmp_name"];
        $error = $_FILES["image"]["error"];
        $target_file = "/profiles/images/$name";
        move_uploaded_file($temp, $target_file);
    }
?>

I've tried echoing out the file name ($name), but it doesn't return anything at all. It's blank for some reason. This is when I try to upload an image. When I echo $target_file, I get this "/profiles/images/", the $name part is not included for some reason.

Aucun commentaire:

Enregistrer un commentaire