Q:

PHP upload script error

Im new to php as to this site... Im trying to make site where you will upload cfg from CSGO. My PHP script for it does not work :(. I want to: write down ip of uploader,check if file name is cfg.rar,check if file uploads/typed username already exist - if yes than read and compare password from password.txt with the typed one - wrong = error/good = delete existing cfg,if file not exist:create dir: uploads/typed username,create file in: password.txt with the typed password,check file size,check file type (.rar),check if upload was aborted
php code: 
<?php
$myfile = fopen("ip.txt", "a") or die("Unable to open file!");
$txt = "\n". $_SERVER['REMOTE_ADDR'];
fwrite($myfile, $txt . basename( $_POST['name']));
fclose($myfile);

$target_dir = "uploads/";
$target_folder = $target_dir . $_POST['name'] . "/";
$target_file = $target_dir . $_POST['name'] . "/" . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
if(basename($_FILES["fileToUpload"]["name"]) == "cfg.rar") {
        echo "FILE IS AN cfg.rar";
        $uploadOk = 1;
    } else {
        echo "FILE IS NOT AN cfg.rar.";
        $uploadOk = 0;
}
// Check if file already exists
if (!file_exists($target_folder)) {
    $password = file_get_contents($target_folder . "password.txt");
    if ($_POST['password'] !== $password) {
    echo "THIS NAME ALREADY EXIST!";
    echo "IF IT'S YOURS, TRY TO RE-ENTER THE PASSWORD!";
    $uploadOk = 0;
    }
    else
    {
        unlink($target_file);
    }
}
else
{
    mkdir($target_folder);
    $fopenh = fopen($target_folder . "/pass.txt", "c");
    fwrite($fopenh, $_POST['password']);
    fclose($fopenh);
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 150000) {
    echo "SORRY, YOUR FILE IS TOO LARGE.";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "rar" ) {
    echo "SORRY, ONLY cfg.rar FILES ARE ALLOWED.";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "SORRY, YOUR FILE WAS NOT UPLOADED.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "THE FILE ". basename( $_FILES["fileToUpload"]["name"]). " HAS BEEN UPLOADED.";
    } else {
        echo "SORRY, THE FILE COULD NOT BE UPLOADED!.";
    }
}
?>`

html code:
<center><form action="upload.php" method="post">
            Username: <input type="text" name="name" id="name"><br/>
            Password: <input type="password" name="password" id="password"><br/>
            Select cfg.rar to upload:<input type="file" name="fileToUpload" id="fileToUpload"><br/><br/>
            <input type="submit" value="UPLOAD" name="submit">
            </form>
            </br>
            <p>By uploading a file you accept, that this site will save your ip address!</p></center>

Thank you for help :)
Going to sleep :3

A:

When dealing with (uploading) files, a valid enctype is required in forms.
Add enctype="multipart/form-data" to your form tags.
Read the manual:

http://php.net/manual/en/features.file-upload.post-method.php

and make sure the folder you are uploading to, has the proper permissions to write to it.
Use error reporting:

http://php.net/manual/en/function.error-reporting.php

