所以我问了一些关于通过PHP / HTML上传大文件的问题,这似乎是我得到的最接近的 -
<!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>
就目前而言,这个脚本适用于较小的文件,但是一旦我发送了更大的文件(大约超过一百兆),一旦文件上传过程完成,页面就会尝试重复(按照预期),但404在这个过程中 - 我似乎无法隔离的问题。任何建议都会很棒。
答案 0 :(得分:1)
尝试将以下内容添加到.htaccess
文件中:
php_value max_execution_time 300
php_value max_input_time 300
php_value upload_max_filesize 200M
php_value post_max_size 200M