I am trying to create an upload system for my website. I want it to display the size of the file as well as the percentage the file takes up of 1GB (example: 512MB would be %50 because 512 is 0.5GB). The way I chose to do this is to create a lot of if, elseif.

Here is my code:

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "udk")
|| ($_FILES["file"]["type"] == "upk")
|| ($_FILES["file"]["type"] == "application/exe")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/bmp")
|| ($_FILES["file"]["type"] == "text/plain")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/gif"))
&& ($_FILES["file"]["size"] < 1073741824)) //1GB of storage.
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    //var_dump($_FILES["file"]["type"]);
    }
  else
    {
    if ($_FILES["file"]["size"] < 107374182.4){
    	$size = "10%";
    }
    elseif ($_FILES["file"]["size"] < 214748364.8){
    	$size = "20%;
    }
    elseif ($_FILES["file"]["size"] < 322122547.2){
    	$size = "30%";
    }
    elseif ($_FILES["file"]["size"] < 429496729.6){
    	$size = "40%";
    }
    elseif ($_FILES["file"]["size"] < 536870912){
    	$size = "50%";
    }
    elseif ($_FILES["file"]["size"] < 644245094.4){
    	$size = "60%";
    }
    elseif ($_FILES["file"]["size"] < 751619276.8){
    	$size = "70%";
    }
    elseif ($_FILES["file"]["size"] < 858993459.2){
    	$size = "80%";
    }
    elseif ($_FILES["file"]["size"] < 966367641.6){
    	$size = "90%";
    }
    elseif ($_FILES["file"]["size"] < 1063004405.76){
    	$size = "99%";
    }
    elseif ($_FILES["file"]["size"] = 1073741824){
    	$size = "100%";
    }
    
    echo "Name: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Percentage used: " . $size;
    
   
    //echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    //var_dump($_FILES["file"]["type"]);
    if (file_exists("dropbox/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. Please rename and try again.";
      }
    else
      {
      $yes = "<a href='/dropbox/" . $_FILES["file"]["name"] . "'>http://upload.creativecodingstudios.com/" . $_FILES["file"]["name"] . "</a>";
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "dropbox/" . $_FILES["file"]["name"]);
      echo $yes;
      //var_dump($_FILES["file"]["type"]);
      }
    }
  }
else
  {
  if (($_FILES["file"]["size"] < 20000)){
  echo "Your file is too big!";
  //var_dump($_FILES["file"]["type"]);
  }
  else{
  echo "Invalid file";
  //var_dump($_FILES["file"]["type"]);
  }
  }
?>

error:

Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/ccstudio/public_html/upload/upload_file.php on line 27

I am brand new to PHP. Are there any errors (other then that) in the code?

Where you have...

elseif ($_FILES["file"]["size"] < 214748364.8){
$size = "20%;

There is a missing closing double quote " .

elseif ($_FILES["file"]["size"] < 214748364.8){
$size = "20%";

Where you have...

elseif ($_FILES["file"]["size"] < 214748364.8){
$size = "20%;

There is a missing closing double quote " .

elseif ($_FILES["file"]["size"] < 214748364.8){
$size = "20%";

:P

thanks for the reply!

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.