Help with PHP Upload Script

I’m working on a website, and I need help on one of the scripts that I am using to upload files.
I have a PHP script that allows the user to select a file to be uploaded, and for small files, it seems to work.
However, if the user tries to upload a bigger file, ~3MB, the script won’t upload the file, and it will end up with Upload Error 7, which is UPLOAD_ERR_CANT_WRITE: Failed to write file to disk.

I’ll attach the scripts here for you to look at.

Here is the HTML form:

<form action="uploader.php" method="post" enctype="multipart/form-data">
    Select file to upload:<br /><br />
    <input type="file" name="fileToUpload" id="fileToUpload"><br /><br />
    <input type="submit" value="Upload File" name="submit">
</form>

Here is the PHP script I use for uploading - uploader.php:
Some info about it:
I get the extension of the file uploaded, and create a folder with the name of the extension, and put the file inside. The directory I store the files in is one folder back, in the files folder.
I’ve seen other people’s posts where they suggested trying to change PHP vars like post_max_size, and I have changed them all accordingly - but the script still does not work. I really need help.

<?php
//Upload Folder
$dir = "../files/";

//Uploaded File
$target_file = $dir . basename($_FILES["fileToUpload"]["name"]);
//File's Extension
$extension = pathinfo($target_file, PATHINFO_EXTENSION);
//Filename
$filename = pathinfo($target_file, PATHINFO_BASENAME);

//The folder that is created for the extension
$location = "{$dir}/{$extension}";
//Where the file is placed in the extension folder
$filelocation = "{$location}/{$filename}";

//The fixed file name, with the location set for where it will be placed.
$target_file_2 = $dir . $extension . "/" . basename($_FILES["fileToUpload"]["name"]);

//Link executed after upload...
$link = "http://test.com";

//Debug: Array showing the file's upload status (where I see it hits the error 07)
print_r($_FILES["fileToUpload"]);

//If extension folder exists/doesn't exist
if(file_exists($location))
{
        //Uploads the uploaded file, and moves it to the target location: ../files/EXTENSION/filename
	move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file_2);
	//header("Location: $link");
}
else
{
        //Creates the Extension folder if it does not exist.
	mkdir($location);
        //Uploads the uploaded file, and moves it to the target location: ../files/EXTENSION/filename
	move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file_2);
	//header("Location: $link");
}
?>

When I try to upload files that are smaller, it is successful, and the debug print shows something like this:

It successfully uploads with 0 errors.
However, if I try to upload a bigger file…

Array ( [name] => testupload.file [type] => [tmp_name] => [error] => 7 [size] => 0 )

It shows that the error I get from uploading is 7, and the size is 0.
I’ve already tried the fixes such as adding “php_value post_max_size 50M” or other fixes to my .htaccess file, nothing seems to work. I can verify that the changes take place, but it still doesn’t fix the upload.
If anyone knows what to do, any help would be sincerely appreciated.

Could it be something to do with the upload_tmp_dir php flag? The default folder for temp files is tmp/ , but is there a limit to the files stored in that folder? And if so, is there any way I can change that folder?

Have you tried to hard code the size, like this:

define('KB', 1024);
define('MB', 1048576);
define('GB', 1073741824);
define('TB', 1099511627776);

     // Check file size 5mb
    if ($_FILES["fileToUpload"]["size"] > 5*MB) {
        echo "Sorry, your file is too large.";
        $uploadOk = 0;
    }

That really wouldn’t be what I’m looking for. I want to allow files bigger than a couple of megabytes, but anything that is bigger than ~3MB doesn’t want to upload. I’m trying to get it so I can upload short mp4 files directly from a page, but anything that is slightly larger than normal doesn’t upload at all. I’m looking for a way to make it so I can upload bigger files, since it doesn’t seem to be working.

Are 000WebHost’s tmp folders file-size restricted? Can I upload big files to the tmp folder, or is the tmp folder restrictive on size?

Is there a way I can change what the temp folder is, using .htaccess?

I have the old version of 000webhost, not the new, so I don’t know what the tmp folder is, sorry. Have you had any luck on this with other forums (stackoverflow for example) @AntiTeal. Also I can only upload 5mb with my PHP script, so I know where you are coming from. Also do you have the free version or premium?