This code works successfully uploading, but I'd like to redirect from that page after upload. I tried a few things without success:

foreach (array('video', 'audio') as $type) {
    if (isset($_FILES["${type}-blob"])) {

        $fileName = $_POST["${type}-filename"];

       $uploadDirectory = 'uploads/' . $fileName;

            // make sure that one can upload only allowed audio/video files
            $allowed = array(
                'webm',
                'wav',
                'mp4',
                'mov'
    );

    $extension = pathinfo($uploadDirectory, PATHINFO_EXTENSION);
    if (!$extension || empty($extension) || !in_array($extension, $allowed)) {
        echo 'Invalid file extension: '.$extension;
        return;
    }

$new_filepath = "uploads/" . uniqid() . ".". $extension;

header( "https://../index.php" );

if(file_exists($_FILES["${type}-blob"]["tmp_name"]) && is_uploaded_file($_FILES["${type}-blob"]["tmp_name"]))
{
if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $new_filepath))
{
	echo 'No upload';
	} else {
		echo 'File uploaded';
	}
}
}
}
?>

any assistance is appreciated

    The header() needs to say what type of header it is, e.g.:

    header('Location: https://../index.php');
    

    You also need to make sure that absolutely nothing (even white-space) is output before the header() call. Additionally, if you don't want any code after it to execute, do an exit; right after it, since it just queues up the HTTP header to be sent whenever output is generated or the script terminates).

      Thanks for your reply. However, I tried this without any redirect success. And when I added the redirect, the echo doesn't display. I look forward to some additional guidance.

      <?php
      header('Content-Length: '.$filesize);
      header("Content-Range: 0-".($filesize-1)."/".$filesize);
      foreach (array('video', 'audio') as $type) {
          if (isset($_FILES["${type}-blob"])) {
              $fileName = $_POST["${type}-filename"];
             $uploadDirectory = 'uploads/' . $fileName;
                  // make sure that one can upload only allowed audio/video files
                  $allowed = array(
                      'webm',
                      'wav',
                      'mp4',
                      'mov'
          );
          $extension = pathinfo($uploadDirectory, PATHINFO_EXTENSION);
          if (!$extension || empty($extension) || !in_array($extension, $allowed)) {
              echo 'Invalid file extension: '.$extension;
              return;
          }
      $new_filepath = "uploads/" . uniqid() . ".". $extension;
      header('Location: https://some-web-name.com/index.php');
      exit();
      if(file_exists($_FILES["${type}-blob"]["tmp_name"]) && is_uploaded_file($_FILES["${type}-blob"]["tmp_name"]))
      {
      if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $new_filepath))
      {
      	echo 'No Upload';
      	} else {
      		echo 'File Uploaded';
      	}
      }
      }
      }
      ?>

        Replaced the back-ticks with [code]...[/code] tags in your post (they format much better than the </> button in the edit window).

        Anyway, I suggest you add some (temporary) code to ensure all warnings are displayed.

        <?php
        ini_set('display_errors', true);
        error_reporting(E_ALL);
        // rest of code...
        

        That will alert you if for some reason the call to header() cannot be executed.

          Meanwhile, you might as well remove those other header calls, too: if you redirect, it'll be to another page with a different size. If you don't redirect you'll just echo a couple of words. And unless $filesize is magically the right length, it won't be the length of those couple of words.

            Write a Reply...