0

So I've asked a few questions about large file upload over PHP/HTML, and this seems to be the closest I've gotten -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Media Upload</title>

<script language="javascript">
  function toggleDiv(divid)
  {
    if(document.getElementById(divid).style.display == 'none')
    {
      document.getElementById(divid).style.display = 'block';
    }
    else
    {
      document.getElementById(divid).style.display = 'none';
    }
  }
</script>

<script>
function validateMediaUpload()
{
    var mediaType = getMediaType();
    var mediaSite = getMediaSite();
    var audioFile = document.forms['mediaUpload']['audioFile'].value;
    var videoFile = document.forms['mediaUpload']['videoFile'].value;

    if( mediaSite == null || mediaSite == "" )
    {
        alert("Please select a Media Site.");
        return false;
    }
    else if( mediaType == null || mediaType == "" )
    {
        alert("Please select a valid Media Type.");
        return false;
    }
    else 
    {
            if( mediaType == "audio" )
            {
                if( audioFile == null || audioFile == "" )
                {
                    alert("Please select an audio file.");
                    return false;
                }
                else
                {
                    showDiv('uploadDiv');
                    return true;
                }
            }
            else if( mediaType == "video" )
            {
                if( videoFile == null || videoFile == "" )
                {
                    alert("Please select a video file.");
                    return false;
                }
                else
                {
                    showDiv('uploadDiv');
                    return true;
                }
            }
            else
            {
                if( audioFile == null || audioFile == "" )
                {
                    alert("Please select an audio file.");
                    return false;
                }
                else if( videoFile == null || videoFile == "" )
                {
                    alert("Please select a video file.");
                    return false;
                }
                else
                {
                    showDiv('uploadDiv');
                    return true;
                }
            }
    }
}

function getMediaType() {
      var radioButtons = document.getElementsByName("mediaType");
      for (var x = 0; x < radioButtons.length; x ++) {
        if (radioButtons[x].checked) {
          return radioButtons[x].value;
        }
      }
    }

function getMediaSite() {
  var radioButtons = document.getElementsByName("mediaSite");
  for (var x = 0; x < radioButtons.length; x ++) {
    if (radioButtons[x].checked) {
      return radioButtons[x].value;
    }
  }
}
</script>

<script language="javascript">
  function showDiv(divid)
  {
    document.getElementById(divid).style.display = 'block';
  }
</script>


<script language="javascript">
  function hideDiv(divid)
  {
    document.getElementById(divid).style.display = 'none';
  }
</script>
</head>

<body>
<?php
// Set the timeout to be longer to allow the file to upload, a value in seconds (3600 = 1 hour)
set_time_limit(0);

// Set these amounts to whatever you need (1M = 1MB)
ini_set("post_max_size", "1000M");
ini_set("upload_max_filesize", "1000M");

// Generally speaking, the memory_limit should be higher than your post size.  So make sure that's right too.
ini_set("memory_limit", "1100M");

if( !isset($_GET['action']))
{
    ?>
    <h3>Upload Media</h3>
    <form action="/alpha_admin/tools/mediaUpload/index.php?action=upload" method="post" enctype="multipart/form-data" name="mediaUpload" id="mediaUpload" onsubmit="return validateMediaUpload();">
     <p>
        <label>Media Site<br />
          <input type="radio" name="mediaSite" value="slospan" id="mediaSiteSlospan" />
          SloSpan</label>
        <br />
        <label>
          <input type="radio" name="mediaSite" value="calspan" id="mediaSiteCalspan" />
          CalSpan</label>
        <br />
      </p>
      <p>
        <label>Media Type<br />
          <input type="radio" name="mediaType" value="audio" id="mediaTypeA" onClick="showDiv('audioDiv'); hideDiv('videoDiv');"/>
          Audio</label>
        <br />
        <label>
          <input type="radio" name="mediaType" value="video" id="mediaTypeV"  onClick="showDiv('videoDiv'); hideDiv('audioDiv');" />
          Video</label>
        <br />
        <label>
          <input type="radio" name="mediaType" value="both" id="mediaTypeB" onClick="showDiv('audioDiv'); showDiv('videoDiv');"/>
          Both</label>
      </p>
      <div id="audioDiv" style="display:none">
        <label for="audioFile">Audio File</label>
        <input type="file" name="audioFile" id="audioFile" />
      </div>
      <br />
      <div id="videoDiv" style="display:none">
        <label for="videoFile">Video File</label>
        <input type="file" name="videoFile" id="videoFile" />
      </div>
      <p>
        <input type="submit" name="button" id="button" value="Upload"/>
      </p>
    </form>
    <div id="uploadDiv" style="display:none">
        Now uploading...
    </div>
    <?
}
else
{
    if( $_GET['action'] == "upload" )
    {
        if( !isset($_POST['mediaType']))
        {
            echo("You did not specify a type of media to upload. Please go back and specify a Media Type.");
        }
        else
        {
            if( $_POST['mediaType'] == "audio" )
            {
                $AudioSplit = explode("_", $_FILES["audioFile"]["name"]);
                $AudioAgency = $AudioSplit[0];
                $AudioDateSplit = explode(".", $AudioSplit[1]);
                $AudioDate = $AudioDateSplit[0];
                $AudioDir =  $AudioAgency . "\\" . $AudioAgency . "_" . $AudioDate . "\\";
                $AudioPath = $AudioDir . "\\" . $_FILES["audioFile"]["name"];
                $FullAudioDir = "d:\\" . $_POST['mediaSite'] . "-media\\audio_files\\" . $AudioDir;
                $FullAudioPath = $FullAudioDir . $_FILES["audioFile"]["name"];

                if( !file_exists($FullAudioDir))
                    mkdir($FullAudioDir);

                echo("Moving audio...");
                move_uploaded_file($_FILES["audioFile"]["tmp_name"], $FullAudioPath );
                echo "<p>Audio uploaded to " . $FullAudioPath .  ".</p>";
            }
            else if( $_POST['mediaType'] == "video" )
            {
                $VideoSplit = explode("_", $_FILES["videoFile"]["name"]);
                $VideoAgency = $VideoSplit[0];
                $VideoDateSplit = explode(".", $VideoSplit[1]);
                $VideoDate = $VideoDateSplit[0];
                $VideoDir =  $VideoAgency . "\\" . $VideoAgency . "_" . $VideoDate . "\\";;
                $VideoPath = $VideoDir . "\\" . $_FILES["videoFile"]["name"];
                $FullVideoDir = "d:\\" . $_POST['mediaSite'] . "-media\\video_files\\" . $VideoDir;
                $FullVideoPath = $FullVideoDir . $_FILES["videoFile"]["name"];

                if( !file_exists($FullVideoDir))
                    mkdir($FullVideoDir);

                echo("Moving video...");
                move_uploaded_file($_FILES["videoFile"]["tmp_name"], $FullVideoPath );
                echo "<p>Media uploaded to " . $FullVideoPath .  ". Thank you!</p>";
            }
            else
            {
                $AudioSplit = explode("_", $_FILES["audioFile"]["name"]);
                $AudioAgency = $AudioSplit[0];
                $AudioDateSplit = explode(".", $AudioSplit[1]);
                $AudioDate = $AudioDateSplit[0];
                $AudioDir =  $AudioAgency . "\\" . $AudioAgency . "_" . $AudioDate . "\\";
                $AudioPath = $AudioDir . "\\" . $_FILES["audioFile"]["name"];
                $FullAudioDir = "d:\\" . $_POST['mediaSite'] . "-media\\audio_files\\" . $AudioDir;
                $FullAudioPath = $FullAudioDir . $_FILES["audioFile"]["name"];

                $VideoSplit = explode("_", $_FILES["videoFile"]["name"]);
                $VideoAgency = $VideoSplit[0];
                $VideoDateSplit = explode(".", $VideoSplit[1]);
                $VideoDate = $VideoDateSplit[0];
                $VideoDir =  $VideoAgency . "\\" . $VideoAgency . "_" . $VideoDate . "\\";;
                $VideoPath = $VideoDir . "\\" . $_FILES["videoFile"]["name"];
                $FullVideoDir = "d:\\" . $_POST['mediaSite'] . "-media\\video_files\\" . $VideoDir;
                $FullVideoPath = $FullVideoDir . $_FILES["videoFile"]["name"];

                if( !file_exists($FullAudioDir))
                    mkdir($FullAudioDir);

                if( !file_exists($FullVideoDir))
                    mkdir($FullVideoDir);

                echo("Moving audio...");
                move_uploaded_file($_FILES["audioFile"]["tmp_name"], $FullAudioPath );
                echo("Moving video...");
                move_uploaded_file($_FILES["videoFile"]["tmp_name"], $FullVideoPath );
                echo "<p>Audio uploaded to " . $FullAudioPath .  ".</p>";
                echo "<p>Video uploaded to " . $FullVideoPath .  ".</p>";
            }
        }
    }
    else if( $_GET['action'] == "progress")
    {
    }
    else
    {
        echo("What'd you do...?");
    }
}
?>
</body>
</html>

As it stands, this script works great for smaller files, however once I send up something larger ( roughly over a hundred megs ), once the file upload process has completed, the page attempts to recur ( as it's supposed to ), but 404's in the process - a problem that I can't seem to isolate. Any recommendations would be great.

1 Answer 1

1

Try adding the following to your .htaccess file:

php_value max_execution_time 300
php_value max_input_time 300
php_value upload_max_filesize 200M
php_value post_max_size 200M
Sign up to request clarification or add additional context in comments.

2 Comments

Upped these values a bit ( will be dealing with larger files than this ) - running a test right now. Will comment if it doesn't work. Thanks.
No fix - upload completes and page switches to 404 with this URL: mydomain.com/alpha_admin/tools/mediaUpload/?action=upload which is accurate. Thanks for the attempt.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.