0

hello I have a simple PHP form that has an input file field and upload button what I want to do is when click the button the file should be uploaded to a directory called uploads but it won't work here is the code.

<?php
if(isset($_FILES['uploadfilefield']))
{
    $uploadName = $_FILES['uploadfilefield']['name'];
    $uploadTmp = $_FILES['uploadfilefield']['tmp_name'];
    $uploadType = $_FILES['uploadfilefield']['type'];

    $uploadName = preg_replace("#[^a-z0-9.]#i","",$uploadName);

    if(!$uploadTmp)
    {
        die("no file Selected,Please Upload Again");
    }
    else
    {
        move_uploaded_file($uploadTmp, "uploads/$uploadName");
    }
}
?>


<!DOCTYPE html>
<html>
<head>
    <title>File Upload</title>

    <style>
        body
        {
            margin: 0;
            padding: 0;
            background: #CCC;
        }
        .fileuploadholder
        {
            width : 400px;
            height: 200px;
            margin: 60px auto 0px auto;
            border: 1px solid #CCC;
            background: #FFF;
            padding: 20px;
            box-sizing: border-box;
        }
    </style>
</head>
<body>

    <div class="fileuploadholder">
        <form method="post" enctype="multipart/form-data" action="index.php">
            <input type="file" name="fileupload" id="uploadfilefield">
            <input type="submit" value="Upload" id="uploadbutton">
        </form>
    </div>
</body>
</html>

and here is a photo of my directoriesenter image description here

and here is inside the directory

enter image description here

Mohammad Istanboli
  • 755
  • 1
  • 8
  • 19

0 Answers0