Well, I am making an upload for people who make games with the Unity game engine. Basically, the engine will build the game and produce an html file and .unity3d file.

here is my html form:

<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Index file:</label>
<input type="file" name="file" id="file" />
<br />
<label for="file2">Unity file:</label>
<input type="file" name="file2" id="file2" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>

and here is my upload_file script:

<?php
if ((($_FILES["file"]["type"] == "text/html")
&& ($_FILES["file2"]["size"] < 8388608)
&& ($_FILES["file"]["size"] < 8388608)))
{
if($_FILES["file2"]["size"] < 8388608){
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    echo "Return Code: " . $_FILES["file2"]["error"] . "<br />";
    }
  else
    {
    $mb = $_FILES["file2"]["size"] / 1048576;
    echo "Done.";
    echo "<br />";
    echo "Index file: " . $_FILES["file"]["name"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "<br />";
    echo "Unity file: " . $_FILES["file2"]["name"] . "<br />";
    echo "Size: " . ($_FILES["file2"]["size"] / 1048576) . "Mb<br />";
    echo "<br />";
    if($mb < 1){
    echo "Space used: [-------------]";
    }
    else if($mb <= 1){
    echo "Space used: [|------------]";
    }
    else if($mb <= 2){
    echo "Space used: [||-----------]";
    }
    else if($mb <= 3){ 
    echo "Space used: [|||----------]";
    }
    else if($mb <= 4){
    echo "Space used: [|||||--------]";
    }
    else if($mb <= 5){
    echo "Space used: [|||||||------]";
    }
    else if($mb <= 6){
    echo "Space used: [|||||||||----]";
    }
    else if($mb <= 7){
    echo "Space used: [|||||||||||--]";
    }
    else if($mb <= 8){
    echo "Space used: [|||||||||||||]";
    }
    echo "<br />";
    echo "<br />";
    $random = rand(100, 999);
    mkdir($random);
    move_uploaded_file($_FILES["file2"]["tmp_name"],
      "upload" . "/" . $_FILES["file"]["name"]);
      move_uploaded_file($_FILES["file"]["tmp_name"],
      $random . "/index.html");
      
      echo "Location: <a href=http://www.creativecodingstudios.com/Unity/" . $random . "/>http://www.creativecodingstudios.com/Unity/" . $random . "/</a>";
      
    }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

But in order for the file to work, it needs the .unity3d program. And for some reason, it's not copying over. Is there something wrong with my code?

It might be a permissions issue with the folder/directory you are randomly creating. You may need to chmod it after you create it.

That didn't work. Google chrome says something is uploading and the stats display the size and everything.


creativecodingstudios.com

for the index file, upload an html document. The next field is the main concern.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.