Jump to content

Upload Progress


Dysan

Recommended Posts

Hi,

 

The following code uploads files to the server. How do I output to the user the progress of the upload, so the user is aware of how long the process is going to take?

 

<?php
if (($_FILES["file"]["type"] == "audio/mp3")
|| ($_FILES["file"]["type"] == "audio/x-mpeg"))
{
  if ($_FILES["file"]["error"] > 0)
  {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  }
  else
  {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
    {
      echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
      $file = ($_FILES["file"]["name"]);
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; 
    }
  }
}
else
{
  echo "Invalid file";
  echo $_FILES["file"]["type"];
}
?>

Link to comment
https://forums.phpfreaks.com/topic/77868-upload-progress/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.